Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
nsImportAddressBooks.cpp File Reference
#include "prthread.h"
#include "prprf.h"
#include "nscore.h"
#include "nsCOMPtr.h"
#include "nsIImportService.h"
#include "nsISupportsArray.h"
#include "nsIImportAddressBooks.h"
#include "nsIImportGeneric.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "nsIImportABDescriptor.h"
#include "nsIImportFieldMap.h"
#include "nsCRT.h"
#include "nsString.h"
#include "nsIURL.h"
#include "nsNetCID.h"
#include "nsIFileSpec.h"
#include "nsILocalFile.h"
#include "nsIAddrDatabase.h"
#include "nsIAddrBookSession.h"
#include "nsIRDFService.h"
#include "nsRDFCID.h"
#include "nsAbBaseCID.h"
#include "nsIAbDirectory.h"
#include "nsIAddressBook.h"
#include "nsImportStringBundle.h"
#include "nsTextFormatter.h"
#include "nsIProxyObjectManager.h"
#include "nsProxiedService.h"
#include "ImportDebug.h"

Go to the source code of this file.

Classes

class  nsImportGenericAddressBooks
class  AddressThreadData

Functions

static NS_DEFINE_CID (kRDFServiceCID, NS_RDFSERVICE_CID)
static NS_DEFINE_CID (kSupportsWStringCID, NS_SUPPORTS_STRING_CID)
static NS_DEFINE_CID (kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID)
 PR_STATIC_CALLBACK (void) ImportAddressThread(void *stuff)
nsresult NS_NewGenericAddressBooks (nsIImportGeneric **aImportGeneric)
nsIAddrDatabaseGetAddressBookFromUri (const char *pUri)
nsIAddrDatabaseGetAddressBook (const PRUnichar *name, PRBool makeNew)

Function Documentation

nsIAddrDatabase* GetAddressBook ( const PRUnichar name,
PRBool  makeNew 
)

Definition at line 758 of file nsImportAddressBooks.cpp.

{
       nsresult                    rv = NS_OK;

       if (!makeNew) {
              // FIXME: How do I get the list of address books and look for a
              // specific name.  Major bogosity!
              // For now, assume we didn't find anything with that name
       }
       
       IMPORT_LOG0( "In GetAddressBook\n");

       nsCOMPtr<nsIProxyObjectManager> proxyMgr = 
                do_GetService(kProxyObjectManagerCID, &rv);
       if (NS_FAILED( rv)) {
              IMPORT_LOG0( "*** Error: Unable to get proxy manager\n");
              return( nsnull);
       }

       nsIAddrDatabase *    pDatabase = nsnull;

       /* Get the profile directory */
       nsCOMPtr<nsILocalFile> dbPath;

       NS_WITH_PROXIED_SERVICE(nsIAddrBookSession, abSession, NS_ADDRBOOKSESSION_CONTRACTID, NS_UI_THREAD_EVENTQ, &rv); 
       
       if (NS_SUCCEEDED(rv))
              rv = abSession->GetUserProfileDirectory(getter_AddRefs(dbPath));
       if (NS_SUCCEEDED(rv)) {
              // Create a new address book file - we don't care what the file
              // name is, as long as it's unique
              rv = dbPath->Append(NS_LITERAL_STRING("impab.mab"));
        if (NS_SUCCEEDED(rv)) {
          rv = dbPath->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
              
          if (NS_SUCCEEDED(rv)) {
            IMPORT_LOG0( "Getting the address database factory\n");

            NS_WITH_PROXIED_SERVICE(nsIAddrDatabase, addrDBFactory, NS_ADDRDATABASE_CONTRACTID, NS_UI_THREAD_EVENTQ, &rv);
            if (NS_SUCCEEDED(rv) && addrDBFactory) {
                       IMPORT_LOG0( "Opening the new address book\n");
                       rv = addrDBFactory->Open( dbPath, PR_TRUE, PR_TRUE, &pDatabase);
            }
          }
        }
       }
       if (NS_FAILED(rv)) {
              IMPORT_LOG0( "Failed to get the user profile directory from the address book session\n");
       }

       
       if (pDatabase) {
              // We made a database, add it to the UI?!?!?!?!?!?!
              // This is major bogosity again!  Why doesn't the address book
              // just handle this properly for me?  Uggggg...
              
              NS_WITH_PROXIED_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, NS_UI_THREAD_EVENTQ, &rv);
              if (NS_SUCCEEDED(rv)) {
                     nsCOMPtr<nsIRDFResource>    parentResource;
                     rv = rdfService->GetResource(NS_LITERAL_CSTRING(kAllDirectoryRoot),
                                   getter_AddRefs(parentResource));
                     nsCOMPtr<nsIAbDirectory> parentDir;
                     /*
                      * TODO
                      * This may not be required in the future since the 
                      * primary listeners of the nsIAbDirectory will be
                      * RDF directory datasource which propagates events to
                      * RDF Observers. In the future the RDF directory datasource
                      * will proxy the observers because asynchronous directory
                      * implementations, such as LDAP, will assert results from
                      * a thread other than the UI thread.
                      *
                      */
                     rv = proxyMgr->GetProxyForObject( NS_UI_THREAD_EVENTQ, NS_GET_IID( nsIAbDirectory),
                            parentResource, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs( parentDir));
                     if (parentDir)
                     {
                            nsCAutoString URI("moz-abmdbdirectory://");
                            nsCAutoString leafName;
                            rv = dbPath->GetNativeLeafName(leafName);
                            if (NS_FAILED(rv)) {
                              IMPORT_LOG0( "*** Error: Unable to get name of database file\n");
                            }
                            else {
                              URI.Append(leafName);
                              rv = parentDir->CreateDirectoryByURI(name, URI.get (), PR_FALSE);
                              if (NS_FAILED(rv))
                                IMPORT_LOG0( "*** Error: Unable to create address book directory\n");
                            }
                     }

                     if (NS_SUCCEEDED(rv))
                       IMPORT_LOG0( "Added new address book to the UI\n");
                     else
                       IMPORT_LOG0( "*** Error: An error occurred while adding the address book to the UI\n");
              }
       }
       
       return( pDatabase);
}

Here is the call graph for this function:

Definition at line 745 of file nsImportAddressBooks.cpp.

{
    nsIAddrDatabase *       pDatabase = nsnull;
    if (pUri) {
        nsresult rv = NS_OK;
        NS_WITH_PROXIED_SERVICE(nsIAddressBook, addressBook, NS_ADDRESSBOOK_CONTRACTID, NS_UI_THREAD_EVENTQ, &rv); 
        if (addressBook)
            rv = addressBook->GetAbDatabaseFromURI(pUri, &pDatabase);
    }

       return pDatabase;
}
static NS_DEFINE_CID ( kRDFServiceCID  ,
NS_RDFSERVICE_CID   
) [static]
static NS_DEFINE_CID ( kSupportsWStringCID  ,
NS_SUPPORTS_STRING_CID   
) [static]
static NS_DEFINE_CID ( kProxyObjectManagerCID  ,
NS_PROXYEVENT_MANAGER_CID   
) [static]

Definition at line 167 of file nsImportAddressBooks.cpp.

{
    NS_PRECONDITION(aImportGeneric != nsnull, "null ptr");
    if (! aImportGeneric)
        return NS_ERROR_NULL_POINTER;
       
       nsImportGenericAddressBooks *pGen = new nsImportGenericAddressBooks();

       if (pGen == nsnull)
              return NS_ERROR_OUT_OF_MEMORY;

       NS_ADDREF( pGen);
       nsresult rv = pGen->QueryInterface( NS_GET_IID(nsIImportGeneric), (void **)aImportGeneric);
       NS_RELEASE( pGen);
    
    return( rv);
}

Here is the call graph for this function:

Definition at line 102 of file TestIPCLocks.cpp.

{
  const char *lockName = (const char *) arg;

  LOG("entering TestThread [lock=%s]\n", lockName);

  nsresult rv;

  RandomSleep(1000, 1100);

  //LOG("done sleeping\n");

  rv = gLockService->AcquireLock(lockName, PR_TRUE);
  if (NS_SUCCEEDED(rv))
  {
    //LOG("acquired lock \"%s\"\n", lockName);
    RandomSleep(500, 1000);
    //LOG("releasing lock \"%s\"\n", lockName);
    rv = gLockService->ReleaseLock(lockName);
    if (NS_FAILED(rv))
    {
      LOG("failed to release lock [rv=%x]\n", rv);
      NS_ERROR("failed to release lock");
    }
  }
  else
  {
    LOG("failed to acquire lock [rv=%x]\n", rv);
    NS_NOTREACHED("failed to acquire lock");
  }

  LOG("exiting TestThread [lock=%s rv=%x]\n", lockName, rv);
}