Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
nsAbAddressCollecter Class Reference

#include <nsAbAddressCollecter.h>

Inheritance diagram for nsAbAddressCollecter:
Inheritance graph
[legend]
Collaboration diagram for nsAbAddressCollecter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsAbAddressCollecter ()
virtual ~nsAbAddressCollecter ()
NS_DECL_ISUPPORTS
NS_DECL_NSIABADDRESSCOLLECTER
NS_DECL_NSIOBSERVER nsresult 
Init ()
void collectAddress (in string aAddress, in boolean aCreateCard, in unsigned long aSendFormat)
void collectUnicodeAddress (in wstring aAddress, in boolean aCreateCard, in unsigned long aSendFormat)
nsIAbCard getCardFromAttribute (in string aName, in string aValue)
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Private Member Functions

nsresult AddCardToAddressBook (nsIAbCard *card)
nsresult AutoCollectScreenName (nsIAbCard *aCard, const char *aEmail, PRBool *aModifiedCard)
nsresult SetNamesForCard (nsIAbCard *senderCard, const char *fullName, PRBool *aModifiedCard)
nsresult SplitFullName (const char *fullName, char **firstName, char **lastName)
nsresult SetAbURI (const char *aURI)

Private Attributes

nsCOMPtr< nsIAddrDatabasem_database
nsCOMPtr< nsIAbDirectorym_directory
nsCString m_abURI

Detailed Description

Definition at line 49 of file nsAbAddressCollecter.h.


Constructor & Destructor Documentation

Definition at line 62 of file nsAbAddressCollecter.cpp.

{
}

Definition at line 66 of file nsAbAddressCollecter.cpp.

Here is the call graph for this function:


Member Function Documentation

Definition at line 346 of file nsAbAddressCollecter.cpp.

{
  NS_ENSURE_ARG_POINTER(card);

  nsCOMPtr <nsIAbCard> addedCard;
  if (m_directory)
    return m_directory->AddCard(card, getter_AddRefs(addedCard));

  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

nsresult nsAbAddressCollecter::AutoCollectScreenName ( nsIAbCard aCard,
const char *  aEmail,
PRBool aModifiedCard 
) [private]

Definition at line 210 of file nsAbAddressCollecter.cpp.

{
  NS_ENSURE_ARG_POINTER(aCard);
  NS_ENSURE_ARG_POINTER(aEmail);
  NS_ENSURE_ARG_POINTER(aModifiedCard);

  *aModifiedCard = PR_FALSE;

  nsXPIDLString screenName;
  nsresult rv = aCard->GetAimScreenName(getter_Copies(screenName));
  NS_ENSURE_SUCCESS(rv,rv);

  // don't override existing screennames
  if (!screenName.IsEmpty())
    return NS_OK;

  const char *atPos = strchr(aEmail, '@');
  
  if (!atPos)
    return NS_OK;
  
  const char *domain = atPos + 1;
 
  if (!domain)
    return NS_OK;
 
  // username in 
  // username@aol.com (America Online)
  // username@cs.com (Compuserve)
  // username@netscape.net (Netscape webmail)
  // are all AIM screennames.  autocollect that info.
  if (strcmp(domain,"aol.com") && 
      strcmp(domain,"cs.com") && 
      strcmp(domain,"netscape.net"))
    return NS_OK;

  NS_ConvertASCIItoUTF16 userName(Substring(aEmail, atPos));

  rv = aCard->SetAimScreenName(userName.get());
  NS_ENSURE_SUCCESS(rv,rv);
  
  *aModifiedCard = PR_TRUE;
  return rv;
}

Here is the call graph for this function:

void nsIAbAddressCollecter::collectAddress ( in string  aAddress,
in boolean  aCreateCard,
in unsigned long  aSendFormat 
) [inherited]
void nsIAbAddressCollecter::collectUnicodeAddress ( in wstring  aAddress,
in boolean  aCreateCard,
in unsigned long  aSendFormat 
) [inherited]

Definition at line 333 of file nsAbAddressCollecter.cpp.

{
  nsresult rv;
  nsCOMPtr<nsIPrefBranch2> pPrefBranchInt(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv,rv);

  rv = pPrefBranchInt->AddObserver(PREF_MAIL_COLLECT_ADDRESSBOOK, this, PR_FALSE);

  nsXPIDLCString prefVal;
  pPrefBranchInt->GetCharPref(PREF_MAIL_COLLECT_ADDRESSBOOK, getter_Copies(prefVal));
  return SetAbURI(prefVal.IsEmpty() ? kPersonalAddressbookUri : prefVal.get());
}

Here is the call graph for this function:

void nsIObserver::observe ( in nsISupports  aSubject,
in string  aTopic,
in wstring  aData 
) [inherited]

Observe will be called when there is a notification for the topic |aTopic|.

This assumes that the object implementing this interface has been registered with an observer service such as the nsIObserverService.

If you expect multiple topics/subjects, the impl is responsible for filtering.

You should not modify, add, remove, or enumerate notifications in the implemention of observe.

Parameters:
aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
aData: Notification specific wide string. subject event.
nsresult nsAbAddressCollecter::SetAbURI ( const char *  aURI) [private]

Definition at line 357 of file nsAbAddressCollecter.cpp.

{
  NS_ENSURE_ARG_POINTER(aURI);

  if (!strcmp(aURI,m_abURI.get()))
    return NS_OK;

  if (m_database) {
    m_database->Commit(nsAddrDBCommitType::kSessionCommit);
    m_database->Close(PR_FALSE);
    m_database = nsnull;
  }
  
  m_directory = nsnull;
  m_abURI = aURI;

  nsresult rv;
  nsCOMPtr<nsIAddrBookSession> abSession = do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv); 
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIAddressBook> addressBook = do_GetService(NS_ADDRESSBOOK_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = addressBook->GetAbDatabaseFromURI(m_abURI.get(), getter_AddRefs(m_database));
  NS_ENSURE_SUCCESS(rv, rv);

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

  nsCOMPtr <nsIRDFResource> resource;
  rv = rdfService->GetResource(m_abURI, getter_AddRefs(resource));
  NS_ENSURE_SUCCESS(rv, rv);

  m_directory = do_QueryInterface(resource, &rv);
  NS_ENSURE_SUCCESS(rv, rv);
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAbAddressCollecter::SetNamesForCard ( nsIAbCard senderCard,
const char *  fullName,
PRBool aModifiedCard 
) [private]

Definition at line 257 of file nsAbAddressCollecter.cpp.

{
  char *firstName = nsnull;
  char *lastName = nsnull;
  *aModifiedCard = PR_FALSE;

  nsXPIDLString displayName;
  nsresult rv = senderCard->GetDisplayName(getter_Copies(displayName));
  NS_ENSURE_SUCCESS(rv,rv);

  // we already have a display name, so don't do anything
  if (!displayName.IsEmpty())
    return NS_OK;

  senderCard->SetDisplayName(NS_ConvertUTF8toUCS2(fullName).get());
  *aModifiedCard = PR_TRUE;

  rv = SplitFullName(fullName, &firstName, &lastName);
  if (NS_SUCCEEDED(rv))
  {
    senderCard->SetFirstName(NS_ConvertUTF8toUCS2(firstName).get());
    
    if (lastName)
      senderCard->SetLastName(NS_ConvertUTF8toUCS2(lastName).get());
  }
  PR_FREEIF(firstName);
  PR_FREEIF(lastName);
  return rv;
}

Here is the call graph for this function:

nsresult nsAbAddressCollecter::SplitFullName ( const char *  fullName,
char **  firstName,
char **  lastName 
) [private]

Definition at line 287 of file nsAbAddressCollecter.cpp.

{
  if (fullName)
  {
    *firstName = nsCRT::strdup(fullName);
    if (!*firstName)
      return NS_ERROR_OUT_OF_MEMORY;

    char *plastSpace = *firstName;
    char *walkName = *firstName;
    char *plastName = nsnull;

    while (walkName && *walkName)
    {
      if (*walkName == ' ')
      {
        plastSpace = walkName;
        plastName = plastSpace + 1;
      }
            
      walkName++;
    }

    if (plastName) 
    {
      *plastSpace = '\0';
      *lastName = nsCRT::strdup(plastName);
    }
  }

  return NS_OK;
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 70 of file nsAbAddressCollecter.h.

Definition at line 68 of file nsAbAddressCollecter.h.

Definition at line 69 of file nsAbAddressCollecter.h.


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