Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
nsImportGenericAddressBooks Class Reference
Inheritance diagram for nsImportGenericAddressBooks:
Inheritance graph
[legend]
Collaboration diagram for nsImportGenericAddressBooks:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsImportGenericAddressBooks ()
virtual ~nsImportGenericAddressBooks ()
NS_DECL_ISUPPORTS NS_IMETHOD GetData (const char *dataId, nsISupports **_retval)
NS_IMETHOD SetData (const char *dataId, nsISupports *pData)
NS_IMETHOD GetStatus (const char *statusKind, PRInt32 *_retval)
NS_IMETHOD WantsProgress (PRBool *_retval)
NS_IMETHOD BeginImport (nsISupportsString *successLog, nsISupportsString *errorLog, PRBool isAddrLocHome, PRBool *_retval)
NS_IMETHOD ContinueImport (PRBool *_retval)
NS_IMETHOD GetProgress (PRInt32 *_retval)
NS_IMETHOD CancelImport (void)
nsISupports GetData (in string dataId)
void SetData (in string dataId, in nsISupports pData)
long GetStatus (in string statusKind)
boolean WantsProgress ()
boolean BeginImport (in nsISupportsString successLog, in nsISupportsString errorLog, in boolean isAddrLocHome)
boolean ContinueImport ()
long GetProgress ()

Static Public Member Functions

static void SetLogs (nsString &success, nsString &error, nsISupportsString *pSuccess, nsISupportsString *pError)
static void ReportError (PRUnichar *pName, nsString *pStream)

Private Member Functions

void GetDefaultLocation (void)
void GetDefaultBooks (void)
void GetDefaultFieldMap (void)

Private Attributes

nsIImportAddressBooksm_pInterface
nsISupportsArraym_pBooks
nsCOMPtr< nsIFileSpecm_pLocation
nsIImportFieldMapm_pFieldMap
PRBool m_autoFind
PRUnicharm_description
PRBool m_gotLocation
PRBool m_found
PRBool m_userVerify
nsISupportsStringm_pSuccessLog
nsISupportsStringm_pErrorLog
PRUint32 m_totalSize
PRBool m_doImport
AddressThreadDatam_pThreadData
char * m_pDestinationUri

Detailed Description

Definition at line 85 of file nsImportAddressBooks.cpp.


Constructor & Destructor Documentation


Member Function Documentation

boolean nsIImportGeneric::BeginImport ( in nsISupportsString  successLog,
in nsISupportsString  errorLog,
in boolean  isAddrLocHome 
) [inherited]
NS_IMETHODIMP nsImportGenericAddressBooks::BeginImport ( nsISupportsString successLog,
nsISupportsString errorLog,
PRBool  isAddrLocHome,
PRBool _retval 
)

Definition at line 554 of file nsImportAddressBooks.cpp.

{
       NS_PRECONDITION(_retval != nsnull, "null ptr");
    if (!_retval)
        return NS_ERROR_NULL_POINTER;

       nsString      success;
       nsString      error;
       
       if (!m_doImport) {
              *_retval = PR_TRUE;
              nsImportStringBundle::GetStringByID( IMPORT_NO_ADDRBOOKS, success);
              SetLogs( success, error, successLog, errorLog);
              return( NS_OK);             
       }
       
       if (!m_pInterface || !m_pBooks) {
              nsImportStringBundle::GetStringByID( IMPORT_ERROR_AB_NOTINITIALIZED, error);
              SetLogs( success, error, successLog, errorLog);
              *_retval = PR_FALSE;
              return( NS_OK);
       }

       if (m_pThreadData) {
              m_pThreadData->DriverAbort();
              m_pThreadData = nsnull;
       }

       NS_IF_RELEASE( m_pSuccessLog);
       NS_IF_RELEASE( m_pErrorLog);
       m_pSuccessLog = successLog;
       m_pErrorLog = errorLog;
       NS_IF_ADDREF( m_pSuccessLog);
       NS_IF_ADDREF( m_pErrorLog);
       
       
       // kick off the thread to do the import!!!!
       m_pThreadData = new AddressThreadData();
       m_pThreadData->books = m_pBooks;
       NS_ADDREF( m_pBooks);
       m_pThreadData->addressImport = m_pInterface;
       NS_ADDREF( m_pInterface);
       m_pThreadData->fieldMap = m_pFieldMap;
       NS_IF_ADDREF( m_pFieldMap);
       m_pThreadData->errorLog = m_pErrorLog;
       NS_IF_ADDREF( m_pErrorLog);
       m_pThreadData->successLog = m_pSuccessLog;
       NS_IF_ADDREF( m_pSuccessLog);
       if (m_pDestinationUri)
              m_pThreadData->pDestinationUri = nsCRT::strdup( m_pDestinationUri);
       m_pThreadData->bAddrLocInput = isAddrLocHome ;
                            
       PRThread *pThread = PR_CreateThread( PR_USER_THREAD, &ImportAddressThread, m_pThreadData, 
                                                               PR_PRIORITY_NORMAL, 
                                                               PR_LOCAL_THREAD, 
                                                               PR_UNJOINABLE_THREAD,
                                                               0);
       if (!pThread) {
              m_pThreadData->ThreadDelete();
              m_pThreadData->DriverDelete();
              m_pThreadData = nsnull;
              *_retval = PR_FALSE;
              nsImportStringBundle::GetStringByID( IMPORT_ERROR_AB_NOTHREAD, error);
              SetLogs( success, error, successLog, errorLog);
       }
       else
              *_retval = PR_TRUE;
                                   
       return( NS_OK);

}

Here is the call graph for this function:

Implements nsIImportGeneric.

Definition at line 680 of file nsImportAddressBooks.cpp.

Here is the call graph for this function:

Definition at line 627 of file nsImportAddressBooks.cpp.

{
    NS_PRECONDITION(_retval != nsnull, "null ptr");
    if (!_retval)
        return NS_ERROR_NULL_POINTER;
       
       *_retval = PR_TRUE;
       if (m_pThreadData) {
              if (m_pThreadData->fatalError)
                     *_retval = PR_FALSE;
       }

       return( NS_OK);
}
nsISupports nsIImportGeneric::GetData ( in string  dataId) [inherited]
NS_IMETHODIMP nsImportGenericAddressBooks::GetData ( const char *  dataId,
nsISupports **  _retval 
)

Definition at line 230 of file nsImportAddressBooks.cpp.

{
    NS_PRECONDITION(_retval != nsnull, "null ptr");
       if (!_retval)
              return NS_ERROR_NULL_POINTER;
       
       nsresult      rv;
       *_retval = nsnull;
       if (!nsCRT::strcasecmp( dataId, "addressInterface")) {
              *_retval = m_pInterface;
              NS_IF_ADDREF( m_pInterface);
       }
       
       if (!nsCRT::strcasecmp( dataId, "addressLocation")) {
              if (!m_pLocation)
                     GetDefaultLocation();
              NS_IF_ADDREF(*_retval = m_pLocation);
       }
       
       if (!nsCRT::strcasecmp( dataId, "addressBooks")) {
              if (!m_pLocation)
                     GetDefaultLocation();
              if (!m_pBooks)
                     GetDefaultBooks();
              *_retval = m_pBooks;
              NS_IF_ADDREF( m_pBooks);
       }
       
       if (!nsCRT::strcasecmp( dataId, "addressDestination")) {
              if (m_pDestinationUri) {
            nsCOMPtr<nsISupportsCString> abString = do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID, &rv);
            NS_ENSURE_SUCCESS(rv, rv);
            abString->SetData(nsDependentCString(m_pDestinationUri));
            NS_IF_ADDREF( *_retval = abString);
              }
       }

       if (!nsCRT::strcasecmp( dataId, "fieldMap")) {
              if (m_pFieldMap) {
                     *_retval = m_pFieldMap;
                     m_pFieldMap->AddRef();
              }
              else {
                     if (m_pInterface && m_pLocation) {
                            PRBool needsIt = PR_FALSE;
                            m_pInterface->GetNeedsFieldMap( m_pLocation, &needsIt);
                            if (needsIt) {
                                   GetDefaultFieldMap();
                                   if (m_pFieldMap) {
                                          *_retval = m_pFieldMap;
                                          m_pFieldMap->AddRef();
                                   }
                            }
                     }
              }
       }

       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", (long)rNum);
              if (m_pInterface) {
                     nsCOMPtr<nsISupportsString> data = do_CreateInstance( kSupportsWStringCID, &rv);
                     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(nsDependentString(pData));
                            *_retval = data;
                            NS_ADDREF( *_retval);
                     }
                     nsCRT::free( pData);
              }
       }

       return( NS_OK);
}

Here is the call graph for this function:

Definition at line 445 of file nsImportAddressBooks.cpp.

{
       if (!m_pInterface || m_pBooks)
              return;
       
       if (!m_pLocation && !m_autoFind)
              return;

       nsresult rv = m_pInterface->FindAddressBooks( m_pLocation, &m_pBooks);
       if (NS_FAILED( rv)) {
              IMPORT_LOG0( "*** Error: FindAddressBooks failed\n");
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 459 of file nsImportAddressBooks.cpp.

{
       if (!m_pInterface || !m_pLocation)
              return;
       
       NS_IF_RELEASE( m_pFieldMap);
       
       nsresult      rv;
       nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
       if (NS_FAILED(rv)) {
              IMPORT_LOG0( "*** Unable to get nsIImportService.\n");
              return;
       }

       rv = impSvc->CreateNewFieldMap( &m_pFieldMap);
       if (NS_FAILED( rv))
              return;
       
       PRInt32       sz = 0;
       rv = m_pFieldMap->GetNumMozFields( &sz);
       if (NS_SUCCEEDED( rv))
              rv = m_pFieldMap->DefaultFieldMap( sz);
       if (NS_SUCCEEDED( rv))
              rv = m_pInterface->InitFieldMap( m_pLocation, m_pFieldMap);
       if (NS_FAILED( rv)) {
              IMPORT_LOG0( "*** Error: Unable to initialize field map\n");
              NS_IF_RELEASE( m_pFieldMap);
       }
}

Here is the call graph for this function:

Definition at line 417 of file nsImportAddressBooks.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 643 of file nsImportAddressBooks.cpp.

{
       // This returns the progress from the the currently
       // running import mail or import address book thread.
    NS_PRECONDITION(_retval != nsnull, "null ptr");
    if (!_retval)
        return NS_ERROR_NULL_POINTER;

       if (!m_pThreadData || !(m_pThreadData->threadAlive)) {
              *_retval = 100;                           
              return( NS_OK);      
       }
       
       PRUint32 sz = 0;
       if (m_pThreadData->currentSize && m_pInterface) {
              if (NS_FAILED( m_pInterface->GetImportProgress( &sz)))
                     sz = 0;
       }
       
       if (m_totalSize)
              *_retval = ((m_pThreadData->currentTotal + sz) * 100) / m_totalSize;
       else
              *_retval = 0;
       
       // never return less than 5 so it looks like we are doing something!
       if (*_retval < 5)
              *_retval = 5;

       // as long as the thread is alive don't return completely
       // done.
       if (*_retval > 99)
              *_retval = 99;

       return( NS_OK);
}

Here is the call graph for this function:

long nsIImportGeneric::GetStatus ( in string  statusKind) [inherited]
NS_IMETHODIMP nsImportGenericAddressBooks::GetStatus ( const char *  statusKind,
PRInt32 _retval 
)

Definition at line 376 of file nsImportAddressBooks.cpp.

{
       NS_PRECONDITION(statusKind != nsnull, "null ptr");
       NS_PRECONDITION(_retval != nsnull, "null ptr");
       if (!statusKind || !_retval)
              return( NS_ERROR_NULL_POINTER);
       
       *_retval = 0;

       if (!nsCRT::strcasecmp( statusKind, "isInstalled")) {
              GetDefaultLocation();
              *_retval = (PRInt32) m_found;
       }

       if (!nsCRT::strcasecmp( statusKind, "canUserSetLocation")) {
              GetDefaultLocation();
              *_retval = (PRInt32) m_userVerify;
       }
       
       if (!nsCRT::strcasecmp( statusKind, "autoFind")) {
              GetDefaultLocation();
              *_retval = (PRInt32) m_autoFind;
       }

       if (!nsCRT::strcasecmp( statusKind, "supportsMultiple")) {
              PRBool        multi = PR_FALSE;
              if (m_pInterface)
                     m_pInterface->GetSupportsMultiple( &multi);
              *_retval = (PRInt32) multi;
       }
       
       if (!nsCRT::strcasecmp( statusKind, "needsFieldMap")) {
              PRBool        needs = PR_FALSE;
              if (m_pInterface && m_pLocation)
                     m_pInterface->GetNeedsFieldMap( m_pLocation, &needs);
              *_retval = (PRInt32) needs;
       }

       return( NS_OK);
}

Here is the call graph for this function:

void nsImportGenericAddressBooks::ReportError ( PRUnichar pName,
nsString pStream 
) [static]

Definition at line 859 of file nsImportAddressBooks.cpp.

{
       if (!pStream)
              return;
       // load the error string
       PRUnichar *pFmt = nsImportStringBundle::GetStringByID( IMPORT_ERROR_GETABOOK);
       PRUnichar *pText = nsTextFormatter::smprintf( pFmt, pName);
       pStream->Append( pText);
       nsTextFormatter::smprintf_free( pText);
       nsImportStringBundle::FreeString( pFmt);
       pStream->AppendWithConversion( NS_LINEBREAK);
}

Here is the call graph for this function:

void nsIImportGeneric::SetData ( in string  dataId,
in nsISupports  pData 
) [inherited]
NS_IMETHODIMP nsImportGenericAddressBooks::SetData ( const char *  dataId,
nsISupports *  pData 
)

Definition at line 319 of file nsImportAddressBooks.cpp.

{
       NS_PRECONDITION(dataId != nsnull, "null ptr");
    if (!dataId)
        return NS_ERROR_NULL_POINTER;

       if (!nsCRT::strcasecmp( dataId, "addressInterface")) {
              NS_IF_RELEASE( m_pInterface);
              if (item)
                     item->QueryInterface( NS_GET_IID(nsIImportAddressBooks), (void **) &m_pInterface);
       }
       if (!nsCRT::strcasecmp( dataId, "addressBooks")) {
              NS_IF_RELEASE( m_pBooks);
              if (item)
                     item->QueryInterface( NS_GET_IID(nsISupportsArray), (void **) &m_pBooks);
       }
       
       if (!nsCRT::strcasecmp( dataId, "addressLocation")) {
              m_pLocation = nsnull;

    if (item) {
      nsresult rv;
      nsCOMPtr <nsILocalFile> location = do_QueryInterface(item, &rv);
      NS_ENSURE_SUCCESS(rv,rv);
      
      rv = NS_NewFileSpecFromIFile(location, getter_AddRefs(m_pLocation));
      NS_ENSURE_SUCCESS(rv,rv);
    }

    if (m_pInterface)
                     m_pInterface->SetSampleLocation(m_pLocation);
       }

       if (!nsCRT::strcasecmp( dataId, "addressDestination")) {
              if (item) {
                     nsCOMPtr<nsISupportsCString> abString;
                     item->QueryInterface( NS_GET_IID(nsISupportsCString), getter_AddRefs( abString));
                     if (abString) {
                            if (m_pDestinationUri)
                                   nsCRT::free( m_pDestinationUri);
                            m_pDestinationUri = nsnull;
                nsCAutoString tempUri;
                abString->GetData(tempUri);
                m_pDestinationUri = ToNewCString(tempUri);
                     }
              }
       }

       if (!nsCRT::strcasecmp( dataId, "fieldMap")) {
              NS_IF_RELEASE( m_pFieldMap);
              if (item)
                     item->QueryInterface( NS_GET_IID(nsIImportFieldMap), (void **) &m_pFieldMap);
       }
       
       return( NS_OK);
}

Here is the call graph for this function:

void nsImportGenericAddressBooks::SetLogs ( nsString success,
nsString error,
nsISupportsString pSuccess,
nsISupportsString pError 
) [static]

Definition at line 539 of file nsImportAddressBooks.cpp.

{
       nsAutoString str;
       if (pSuccess) {
              pSuccess->GetData(str);
        str.Append(success);
        pSuccess->SetData(success);
       }
       if (pError) {
              pError->GetData(str);
        str.Append(error);
        pError->SetData(error);
       }      
}

Here is the caller graph for this function:

Definition at line 490 of file nsImportAddressBooks.cpp.

{
       NS_PRECONDITION(_retval != nsnull, "null ptr");
    if (!_retval)
        return NS_ERROR_NULL_POINTER;
       
       if (m_pThreadData) {
              m_pThreadData->DriverAbort();
              m_pThreadData = nsnull;
       }

       GetDefaultLocation();
       GetDefaultBooks();

       PRUint32             totalSize = 0;
       PRBool               result = PR_FALSE;

       if (m_pBooks) {
              PRUint32             count = 0;
              nsresult             rv = m_pBooks->Count( &count);
              PRUint32             i;
              PRBool               import;
              PRUint32             size;
              
              for (i = 0; i < count; i++) {
                     nsCOMPtr<nsIImportABDescriptor> book =
                            do_QueryElementAt(m_pBooks, i);
                     if (book) {
                            import = PR_FALSE;
                            size = 0;
                            rv = book->GetImport( &import);
                            if (import) {
                                   rv = book->GetSize( &size);
                                   result = PR_TRUE;
                            }
                            totalSize += size;
                     }
              }

              m_totalSize = totalSize;
       }
       
       m_doImport = result;

       *_retval = result;   

       return( NS_OK);
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 130 of file nsImportAddressBooks.cpp.

Definition at line 131 of file nsImportAddressBooks.cpp.

Definition at line 138 of file nsImportAddressBooks.cpp.

Definition at line 133 of file nsImportAddressBooks.cpp.

Definition at line 132 of file nsImportAddressBooks.cpp.

Definition at line 127 of file nsImportAddressBooks.cpp.

Definition at line 140 of file nsImportAddressBooks.cpp.

Definition at line 136 of file nsImportAddressBooks.cpp.

Definition at line 129 of file nsImportAddressBooks.cpp.

Definition at line 126 of file nsImportAddressBooks.cpp.

Definition at line 128 of file nsImportAddressBooks.cpp.

Definition at line 135 of file nsImportAddressBooks.cpp.

Definition at line 139 of file nsImportAddressBooks.cpp.

Definition at line 137 of file nsImportAddressBooks.cpp.

Definition at line 134 of file nsImportAddressBooks.cpp.


The documentation for this class was generated from the following file: