Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions
ABChangedMonitor Class Reference

List of all members.

Public Member Functions

(void- ABChanged:

Detailed Description

Definition at line 118 of file nsAbOSXDirectory.mm.


Member Function Documentation

- (void) ABChanged: (NSNotification *)  aNotification

Definition at line 123 of file nsAbOSXDirectory.mm.

                :(NSNotification *)aNotification
{
    NSDictionary *changes = [aNotification userInfo];

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

    NSArray *inserted = [changes objectForKey:kABInsertedRecords];
    if (inserted) {
        nsCOMPtr<nsIRDFResource> resource;
        rv = rdfService->GetResource(NS_LITERAL_CSTRING("moz-abOSXdirectory:///"),
                                     getter_AddRefs(resource));
        NS_ENSURE_SUCCESS(rv, );

        nsCOMPtr<nsIAbOSXDirectory> osxDirectory =
            do_QueryInterface(resource, &rv);
        NS_ENSURE_SUCCESS(rv, );

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

        unsigned int i, count = [inserted count];
        for (i = 0; i < count; ++i) {
            ABAddressBook *addressBook =
                 [ABAddressBook sharedAddressBook];
            ABRecord *card =
                [addressBook recordForUniqueId:[inserted objectAtIndex:i]];
            if ([card isKindOfClass:[ABGroup class]]) {
                nsCOMPtr<nsIAbDirectory> directory;
                ConvertToGroupResource(rdfService, [inserted objectAtIndex:i],
                                       getter_AddRefs(directory));

                rv = osxDirectory->AssertDirectory(abSession, directory);
                NS_ENSURE_SUCCESS(rv, );
            }
            else {
                nsCOMPtr<nsIAbCard> abCard;
                ConvertToCard(rdfService, card, getter_AddRefs(abCard));

                rv = osxDirectory->AssertCard(abSession, abCard);
                NS_ENSURE_SUCCESS(rv, );
            }
        }
    }

    NSArray *updated = [changes objectForKey:kABUpdatedRecords];
    if (updated) {
        unsigned int i, count = [updated count];
        for (i = 0; i < count; ++i) {
            NSString *uid = [updated objectAtIndex:i];
            Update(rdfService, uid);
        }
    }

    NSArray *deleted = [changes objectForKey:kABDeletedRecords];
    if (deleted) {
        nsCOMPtr<nsIRDFResource> resource;
        rv = rdfService->GetResource(NS_LITERAL_CSTRING("moz-abOSXdirectory:///"),
                                     getter_AddRefs(resource));
        NS_ENSURE_SUCCESS(rv, );

        nsCOMPtr<nsIAbOSXDirectory> osxDirectory =
            do_QueryInterface(resource, &rv);
        NS_ENSURE_SUCCESS(rv, );

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

        unsigned int i, count = [deleted count];
        for (i = 0; i < count; ++i) {
            ABAddressBook *addressBook = [ABAddressBook sharedAddressBook];
            NSString *recordClass =
                [addressBook recordClassFromUniqueId:[deleted objectAtIndex:i]];
            if ([recordClass isEqualToString:@"ABGroup"]) {
                nsCOMPtr<nsIAbDirectory> directory;
                ConvertToGroupResource(rdfService, [deleted objectAtIndex:i],
                                       getter_AddRefs(directory));

                rv = osxDirectory->UnassertDirectory(abSession, directory);
                NS_ENSURE_SUCCESS(rv, );
            }
            else {
                nsCOMPtr<nsIAbCard> abCard;
                ConvertToCard(rdfService, [deleted objectAtIndex:i],
                              getter_AddRefs(abCard));

                rv = osxDirectory->UnassertCard(abSession, abCard);
                NS_ENSURE_SUCCESS(rv, );
            }
        }
    }

    if (!inserted && !updated && !deleted) {
        // XXX This is supposed to mean "everything was updated", but we get
        //     this whenever something has changed, so not sure what to do.
    }

    [[aNotification object] release];
}

Here is the call graph for this function:


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