×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    15

    contact database change event details

    Hi everybody,

    I develop the code for retrieving the type of event change & id of the contact item of the contact database.I have posted the code which i developed,
    database= CContactDatabase::OpenL(); //open phonebook, which returns a pointer
    if(database)
    {
    TContactDbObserverEvent event;
    MContactDbObserver* observer;
    TUint connectionid = database->ConnectionId();
    event.iConnectionId = connectionid;
    changenotifier = CContactChangeNotifier::NewL(*database,(MContactDbObserver*) observer);
    CleanupStack::PushL(changenotifier);
    HandleDatabaseEventL((TContactDbObserverEvent)event);
    TContactDbObserverEventType type = event.iType;
    TContactItemId contactitemId = event.iContactId;
    CleanupStack::PopAndDestroy(1);
    }
    but it retrieving the type of the change event has 64 & contact item Id has zero.please tell me,what is the probelm with this code ,if anyboby worked with this ,please send me sample code.thanks in advance .

    with regards,
    r.sajithali.

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    371
    Hi,

    In order to make an application receive events about contact database changes, the MContactDbObserver base class must be inherited by a class that implements the notification, and HandleDatabaseEventL() virtual function of the base class must be implemented. The class defines only one virtual function, which is called by the system when a contact database event occurs.

    class CMyContactApp : public McontactDbObserver
    {
    public:
    // any public data and functions
    CMyContactApp();
    // override the virtual function from the base class
    virtual void HandleDatabaseEventL(TContactDbObserverEvent aEvent);

    private:
    // any private data and functions

    };

    // handling contact database events
    void CMyContactApp::HandleDatabaseEventL(TContactDbObserverEvent aEvent)
    {
    ¡_ // Event handling code
    }

    In addition, the application must create the CContactChangeNotifier object to register itself to receive events.

    CContactDatabase* contactDb = CContactDatabase::OpenL();
    CMyContactApp contactDbObserver;

    CContactChangeNotifier* notifier = CContactChangeNotifier::NewL(*contactDb, contactDbObserver);


    Hopefully this helps!

    Best Regards,
    Marko / Forum Nokia

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    15

    contact database change event details

    Hi marko,

    I tried with the prototype which you posted,For ex, if i deleted the one contact details from the phone book of the nokia 7650.for that it has to retrieve the exact event & contact id ,but it is not retrieving.I have posted code which i did,it retrieving chunk values.please do the needful.


    void CMyContactApp::HandleDatabaseEventL(TContactDbObserverEvent aEvent)
    {
    type = aEvent.iType;
    contactitemId = aEvent.iContactId;
    }


    database= CContactDatabase::OpenL(); //open phonebook, which returns a pointer

    if(database)
    {
    CMyContactApp contactDbObserver;
    TUint connectionid =database->ConnectionId();
    TContactDbObserverEvent event ;
    event.iConnectionId = connectionid;
    changenotifier = CContactChangeNotifier::NewL(*database,&contactDbObserver);
    cleanupStack::PushL(changenotifier);
    contactDbObserver.HandleDatabaseEventL(event);
    TContactDbObserverEventType type = contactDbObserver.type;
    TContactItemId contactitemId = contactDbObserver.contactitemId;
    CleanupStack::PopAndDestroy(1);
    delete database;

    }

  4. #4
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    371
    Hello,

    By looking your code I think you have misunderstood the way the change notifier works. The change notifier uses a callback object (observer), which is called by the system. After you have created CContactChangeNotifier object with a reference to the contact db observer as a parameter, the contact database calls the HandleDatabaseEventL() whenever a change occurs. You don't need to call it explicitly by yourself. You get the type of the change event and contact item Id from the parameter of the HandleDatabaseEventL() .

    Best Regards,
    Marko / Forum Nokia

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    15

    contact database change event details

    Hi marko,

    Thanks for the information.for example If i made changes in phone book of nokia 7650 ,it will automatically trap the corresponding event or not.I have created a new contact item or update or delete the contact item from the contact database,it has to trap the event automatically,but it has not happening why? please give suggestion .thanks in advance.

    with regards,
    r.sajithali.

  6. #6
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    371
    So, You have to implement an observer (MContactDbObserver) and register it using the CContactChangeNotifier, and you will get the events automatically. I just tested it with the emulator in a way I demonstrated in my first message and it should work.

    You have to understand the asynchronous mechanism it uses.

    Best Regards,
    Marko / Forum Nokia

  7. #7
    Registered User
    Join Date
    Mar 2003
    Posts
    8

    Contact database and event trapping for change in a field in Card

    Hello maokkone and sajithali
    I am also developing the same kind of application which reads the contact database
    and save it to the oracle server.I want to trap the events happening on a particular
    contact card say First Name:maokkone Last Name:HHH Cell: 98080080 job: Nokia expert
    if i am changing the cell field of ur contact card whether i will be able to know the event so
    that i will only read a single card and save it to the database instead of read/saving all the contact
    card.
    Maokone u have said in ur discussion that u have tested the code on emulator, can i get the same code,it will be
    a great help for me for my application.

    U have also told abt asynchronous mechanism what does that mean.It will be helpful if u
    make it more clearer so that we can design our application according to that.


    Thanks and Regards
    Tom

  8. #8
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    371
    Hello,

    The asynchronous mechanism is really the same as the observer desing pattern. You should be familiar with that, because it is really common in Symbian programming.

    My testing code is as simple as this:

    void CContactsObsAppUi::ConstructL()
    {
    BaseConstructL();
    iAppContainer = new (ELeave) CContactsObsContainer;
    iAppContainer->SetMopParent(this);
    iAppContainer->ConstructL( ClientRect() );
    AddToStackL( iAppContainer );

    // Open Contact DB
    iContactDb = CContactDatabase::OpenL();
    // Create an observer object from my own observer class
    iContactDbObserver = CContactsObserver::NewL();

    // Register my observer
    iNotifier = CContactChangeNotifier::NewL(*iContactDb, iContactDbObserver);

    }


    void CContactsObserver::HandleDatabaseEventL(TContactDbObserverEvent aEvent)
    {
    TBuf<30> buf;

    buf.Append(_L("Type: "));
    buf.AppendNum(aEvent.iType);
    buf.Append(_L("\nId: "));
    buf.AppendNum(aEvent.iContactId);

    CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
    globalNote->ShowNoteL(EAknGlobalErrorNote, buf);
    CleanupStack::PopAndDestroy();

    }

    Rest of the code does not contain anything special.

    Best Regards,
    Marko / Forum Nokia

  9. #9
    Registered User
    Join Date
    Mar 2003
    Posts
    36

    linking error

    i'm getting a linker error when i try to do this that usually indicates that i'm missing the appropriate library from my .mmp file. here's the error:

    error LNK2001: unresolved external symbol "public: virtual void __thiscall CMyClass::HandleDatabaseEventL(struct TContactDbObserverEvent)


    what is the appropriate library to include, the documentation doesn't say.

    thanks.

  10. #10
    Registered User
    Join Date
    Mar 2003
    Posts
    36

    never mind

    i made a simple, unrelated error.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×