Back to index

lightning-sunbird  0.9+nobinonly
Defines | Enumerations | Functions | Variables
nsAddressBook.cpp File Reference
#include "nscore.h"
#include "nsIAddressBook.h"
#include "nsAddressBook.h"
#include "nsAbBaseCID.h"
#include "nsDirPrefs.h"
#include "nsIAddrBookSession.h"
#include "nsIAbLDIFService.h"
#include "nsAddrDatabase.h"
#include "nsIOutputStream.h"
#include "nsNetUtil.h"
#include "msgCore.h"
#include "nsIImportService.h"
#include "nsIStringBundle.h"
#include "plstr.h"
#include "prmem.h"
#include "prprf.h"
#include "nsCOMPtr.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFResource.h"
#include "nsRDFResource.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsIDOMWindowInternal.h"
#include "nsIContentViewer.h"
#include "nsIDocShell.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsICategoryManager.h"
#include "nsIAbUpgrader.h"
#include "nsIFilePicker.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefLocalizedString.h"
#include "nsIAbCard.h"
#include "nsIAbMDBCard.h"
#include "plbase64.h"
#include "nsIWindowWatcher.h"
#include "nsEscape.h"
#include "nsVCard.h"
#include "nsVCardObj.h"
#include "nsISupportsPrimitives.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsAutoPtr.h"
#include "nsIMsgVCardService.h"
#include "nsCRT.h"

Go to the source code of this file.

Defines

#define LDIF_LINEBREAK   "\015\012"
#define LDIF_LINEBREAK_LEN   2
#define MOZ_AB_OBJECTCLASS   "mozillaAbPersonAlpha"
#define CSV_DELIM   ","
#define CSV_DELIM_LEN   1
#define TAB_DELIM   "\t"
#define TAB_DELIM_LEN   1
#define LDIF_DELIM   (nsnull)
#define LDIF_DELIM_LEN   0
#define CSV_FILE_EXTENSION   ".csv"
#define TAB_FILE_EXTENSION   ".tab"
#define TXT_FILE_EXTENSION   ".txt"
#define LDIF_FILE_EXTENSION   ".ldi"
#define LDIF_FILE_EXTENSION2   ".ldif"

Enumerations

enum  ADDRESSBOOK_EXPORT_FILE_TYPE { LDIF_EXPORT_TYPE = 0, CSV_EXPORT_TYPE = 1, TAB_EXPORT_TYPE = 2 }

Functions

 NS_IMPL_QUERY_INTERFACE4 (nsAddressBook, nsIAddressBook, ICOMMANDLINEHANDLER, nsIContentHandler, nsIStreamLoaderObserver) NS_IMETHODIMP nsAddressBook
char * getCString (VObject *vObj)
static void convertNameValue (VObject *vObj, nsIAbCard *aCard)
static void convertFromVObject (VObject *vObj, nsIAbCard *aCard)
static nsresult addProperty (char **currentVCard, const char *currentRoot, const char *mask)

Variables

const ExportAttributesTableStruct EXPORT_ATTRIBUTES_TABLE [EXPORT_ATTRIBUTES_TABLE_COUNT]

Define Documentation

#define CSV_DELIM   ","

Definition at line 506 of file nsAddressBook.cpp.

Definition at line 507 of file nsAddressBook.cpp.

#define CSV_FILE_EXTENSION   ".csv"

Definition at line 513 of file nsAddressBook.cpp.

Definition at line 510 of file nsAddressBook.cpp.

Definition at line 511 of file nsAddressBook.cpp.

Definition at line 516 of file nsAddressBook.cpp.

Definition at line 517 of file nsAddressBook.cpp.

#define LDIF_LINEBREAK   "\015\012"

Definition at line 106 of file nsAddressBook.cpp.

Definition at line 107 of file nsAddressBook.cpp.

#define MOZ_AB_OBJECTCLASS   "mozillaAbPersonAlpha"

Definition at line 113 of file nsAddressBook.cpp.

#define TAB_DELIM   "\t"

Definition at line 508 of file nsAddressBook.cpp.

Definition at line 509 of file nsAddressBook.cpp.

#define TAB_FILE_EXTENSION   ".tab"

Definition at line 514 of file nsAddressBook.cpp.

#define TXT_FILE_EXTENSION   ".txt"

Definition at line 515 of file nsAddressBook.cpp.


Enumeration Type Documentation

Enumerator:
LDIF_EXPORT_TYPE 
CSV_EXPORT_TYPE 
TAB_EXPORT_TYPE 

Definition at line 519 of file nsAddressBook.cpp.


Function Documentation

static nsresult addProperty ( char **  currentVCard,
const char *  currentRoot,
const char *  mask 
) [static]

Definition at line 1354 of file nsAddressBook.cpp.

{
    // keep in mind as we add properties that we want to filter out any begin and end vcard types....because
    // we add those automatically...
    
    const char *beginPhrase = "begin";
    
    nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
    if (currentVCard && prefBranch)
    {
        PRUint32 childCount;
        char **childArray;
        nsresult rv = prefBranch->GetChildList(currentRoot, &childCount, &childArray);
        NS_ENSURE_SUCCESS(rv, rv);
        
        for (PRUint32 i = 0; i < childCount; ++i) 
        {
            char *child = childArray[i];

            if (!strcmp(child, currentRoot))
                continue;
                
            // first iterate over the child in case the child has children    
            addProperty(currentVCard, child, mask);
               
            // child length should be greater than the mask....
            if (strlen(child) > strlen(mask) + 1)  // + 1 for the '.' in .property
            {
                nsXPIDLCString value;
                prefBranch->GetCharPref(child, getter_Copies(value));
                if (mask)
                    child += strlen(mask) + 1;  // eat up the "mail.identity.vcard" part...
                // turn all '.' into ';' which is what vcard format uses
                char * marker = strchr(child, '.');
                while (marker)
                {
                    *marker = ';';
                    marker = strchr(child, '.');
                }
                
                // filter property to make sure it is one we want to add.....
                if ((PL_strncasecmp(child, beginPhrase, strlen(beginPhrase)) != 0) && (PL_strncasecmp(child, VCEndProp, strlen(VCEndProp)) != 0))
                {
                    if (!value.IsEmpty()) // only add the value is not an empty string...
                        if (*currentVCard)
                        {
                            char * tempString = *currentVCard;
                            *currentVCard = PR_smprintf ("%s%s:%s%s", tempString, child, value.get(), "\n");
                            PR_FREEIF(tempString);
                        }
                        else
                            *currentVCard = PR_smprintf ("%s:%s%s", child, value.get(), "\n");
                }
            }
            else {
                NS_ASSERTION(0, "child length should be greater than the mask");
            }
        }     
        NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(childCount, childArray);
    } 
    return NS_OK;
}

Here is the call graph for this function:

static void convertFromVObject ( VObject vObj,
nsIAbCard aCard 
) [static]

Definition at line 1174 of file nsAddressBook.cpp.

{
    if (vObj)
    {
        VObjectIterator t;

        convertNameValue(vObj, aCard);
        
        initPropIterator(&t, vObj);
        while (moreIteration(&t))
        {
            VObject * nextObject = nextVObject(&t);
            convertFromVObject(nextObject, aCard);
        }
    }
    return;
}

Here is the call graph for this function:

static void convertNameValue ( VObject vObj,
nsIAbCard aCard 
) [static]

Definition at line 1108 of file nsAddressBook.cpp.

{
  const char *cardColName = NULL;

  // if the vCard property is not a root property then we need to determine its exact property.
  // a good example of this is VCTelephoneProp, this prop has four objects underneath it:
  // fax, work and home and cellular.
  if (PL_strcasecmp(VCCityProp, vObjectName(vObj)) == 0)
      cardColName = kWorkCityColumn;
  else if (PL_strcasecmp(VCTelephoneProp, vObjectName(vObj)) == 0)
  {
      if (isAPropertyOf(vObj, VCFaxProp))
          cardColName = kFaxColumn;
      else if (isAPropertyOf(vObj, VCWorkProp))
          cardColName = kWorkPhoneColumn; 
      else if (isAPropertyOf(vObj, VCHomeProp))
          cardColName = kHomePhoneColumn;
      else if (isAPropertyOf(vObj, VCCellularProp))
          cardColName = kCellularColumn;
      else if (isAPropertyOf(vObj, VCPagerProp))
          cardColName = kPagerColumn;
      else
          return;
  }
  else if (PL_strcasecmp(VCEmailAddressProp, vObjectName(vObj)) == 0)
      cardColName = kPriEmailColumn;
  else if (PL_strcasecmp(VCFamilyNameProp, vObjectName(vObj)) == 0) 
      cardColName = kLastNameColumn;
  else if (PL_strcasecmp(VCFullNameProp, vObjectName(vObj)) == 0)
      cardColName = kDisplayNameColumn;
  else if (PL_strcasecmp(VCGivenNameProp, vObjectName(vObj)) == 0)
      cardColName = kFirstNameColumn;
  else if (PL_strcasecmp(VCOrgNameProp, vObjectName(vObj)) == 0) 
      cardColName = kCompanyColumn;
  else if (PL_strcasecmp(VCOrgUnitProp, vObjectName(vObj)) == 0)
      cardColName = kDepartmentColumn;
  else if (PL_strcasecmp(VCPostalCodeProp, vObjectName(vObj)) == 0) 
      cardColName = kWorkZipCodeColumn;
  else if (PL_strcasecmp(VCRegionProp, vObjectName(vObj)) == 0)
      cardColName = kWorkStateColumn;
  else if (PL_strcasecmp(VCStreetAddressProp, vObjectName(vObj)) == 0)
      cardColName = kWorkAddressColumn;
  else if (PL_strcasecmp(VCPostalBoxProp, vObjectName(vObj)) == 0) 
      cardColName = kWorkAddress2Column;
  else if (PL_strcasecmp(VCCountryNameProp, vObjectName(vObj)) == 0)
      cardColName = kWorkCountryColumn;
  else if (PL_strcasecmp(VCTitleProp, vObjectName(vObj)) == 0) 
      cardColName = kJobTitleColumn;
  else if (PL_strcasecmp(VCUseHTML, vObjectName(vObj)) == 0) 
      cardColName = kPreferMailFormatColumn;
  else if (PL_strcasecmp(VCNoteProp, vObjectName(vObj)) == 0) 
      cardColName = kNotesColumn;
  else if (PL_strcasecmp(VCURLProp, vObjectName(vObj)) == 0)
      cardColName = kWebPage1Column;
  else
      return;
  
  if (!VALUE_TYPE(vObj))
      return;

  char *cardColValue = getCString(vObj);
  aCard->SetCardValue(cardColName, NS_ConvertUTF8toUCS2(cardColValue).get());
  PR_FREEIF(cardColValue);
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* getCString ( VObject vObj)

Definition at line 1099 of file nsAddressBook.cpp.

{
    if (VALUE_TYPE(vObj) == VCVT_USTRINGZ)
        return fakeCString(vObjectUStringZValue(vObj));
    if (VALUE_TYPE(vObj) == VCVT_STRINGZ)
        return PL_strdup(vObjectStringZValue(vObj));
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 184 of file nsAddressBook.cpp.

{
  NS_ENSURE_ARG_POINTER(aProperties);

  nsresult rv;

  nsCOMPtr<nsIRDFService> rdfService = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIRDFResource> parentResource;
  rv = rdfService->GetResource(NS_LITERAL_CSTRING(kAllDirectoryRoot),
                               getter_AddRefs(parentResource));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIAbDirectory> parentDir = do_QueryInterface(parentResource, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = parentDir->CreateNewDirectory(aProperties);
  return rv;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 115 of file nsAddressBook.cpp.