locationdataharvester/geocodeupdate/src/geocodeupdate.cpp
changeset 31 8db05346071b
parent 30 96df3ab41000
child 35 59575560d1e6
equal deleted inserted replaced
30:96df3ab41000 31:8db05346071b
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description: 
    14  * Description: 
    15 *
    15  *
    16 */
    16  */
    17 
    17 
    18 #include <qcontactgeolocation.h>
    18 #include <qcontactgeolocation.h>
    19 #include <qcontactmanager.h>
    19 #include <qcontactmanager.h>
    20 #include <qtcontacts.h>
    20 #include <qtcontacts.h>
    21 #include <cntdef.h>
    21 #include <cntdef.h>
    32 
    32 
    33 
    33 
    34 // ----------------------------------------------------------------------------
    34 // ----------------------------------------------------------------------------
    35 // GeocodeUpdate::GeocodeUpdate()
    35 // GeocodeUpdate::GeocodeUpdate()
    36 // ----------------------------------------------------------------------------
    36 // ----------------------------------------------------------------------------
    37 GeocodeUpdate::GeocodeUpdate()
    37 GeocodeUpdate::GeocodeUpdate() :
       
    38     mAgendaUtil(NULL), mUtilInstanceCreated(false)
    38 {
    39 {
    39     
    40     mAgendaUtil = new AgendaUtil();
       
    41     connect(mAgendaUtil, SIGNAL(instanceViewCreationCompleted(int)), this,
       
    42         SLOT(agendautilInstanceCreated(int)));
    40 }
    43 }
    41 
    44 
    42 // ----------------------------------------------------------------------------
    45 // ----------------------------------------------------------------------------
    43 // GeocodeUpdate::~GeocodeUpdate()
    46 // GeocodeUpdate::~GeocodeUpdate()
    44 // ----------------------------------------------------------------------------
    47 // ----------------------------------------------------------------------------
    45 GeocodeUpdate::~GeocodeUpdate()
    48 GeocodeUpdate::~GeocodeUpdate()
    46 {
    49 {
    47     __TRACE_CALLSTACK;
    50     __TRACE_CALLSTACK;
    48     
    51     if (mUtilInstanceCreated) {
       
    52         delete mAgendaUtil;
       
    53     }
    49 }
    54 }
    50 
    55 
    51 // ----------------------------------------------------------------------------
    56 // ----------------------------------------------------------------------------
    52 // GeocodeUpdate::createContactdb()
    57 // GeocodeUpdate::createContactdb()
    53 // ----------------------------------------------------------------------------
    58 // ----------------------------------------------------------------------------
    61 
    66 
    62 // ----------------------------------------------------------------------------
    67 // ----------------------------------------------------------------------------
    63 // CGeocodeUpdate::updateGeocodeToContactDB()
    68 // CGeocodeUpdate::updateGeocodeToContactDB()
    64 // Geo-cordinate updation to contact db  
    69 // Geo-cordinate updation to contact db  
    65 // ----------------------------------------------------------------------------
    70 // ----------------------------------------------------------------------------
    66 bool GeocodeUpdate::updateGeocodeToContactDB(const quint32 contactId,
    71 bool GeocodeUpdate::updateGeocodeToContactDB(const quint32 contactId, const int addressType,
    67         const int addressType, const double latitude,
    72     const double latitude, const double longitude)
    68         const double longitude)
       
    69 
    73 
    70 {
    74 {
    71     __TRACE_CALLSTACK;
    75     __TRACE_CALLSTACK;
    72     QContactManager* contactManger = NULL;
    76     QContactManager* contactManger = NULL;
    73     MYLOCLOGSTRING("call to create contactManger object .");
    77     MYLOCLOGSTRING("call to create contactManger object .");
    74     contactManger = new QContactManager("symbian");
    78     contactManger = new QContactManager("symbian");
    75     MYLOCLOGSTRING("contactManger object created .");
    79     MYLOCLOGSTRING("contactManger object created .");
    76 
    80 
    77     MYLOCLOGSTRING("contactManger object is not null .");
    81     MYLOCLOGSTRING("contactManger object is not null .");
    78     QContact contact = contactManger->contact( contactId );
    82     QContact contact = contactManger->contact(contactId);
    79     QContactGeoLocation location;
    83     QContactGeoLocation location;
    80 
    84 
    81     switch (addressType)
    85     switch (addressType) {
    82     {
       
    83         case ESourceContactsPref:
    86         case ESourceContactsPref:
    84         {
    87         {
    85             break;
    88             break;
    86         }
    89         }
    87         case ESourceContactsWork:
    90         case ESourceContactsWork:
    94             location.setContexts(QContactDetail::ContextHome);
    97             location.setContexts(QContactDetail::ContextHome);
    95             break;
    98             break;
    96         }
    99         }
    97         default:
   100         default:
    98         {
   101         {
    99             return false;       
   102             return false;
   100         }
   103         }
   101     }
   104     }
   102     location.setLongitude(longitude);
   105     location.setLongitude(longitude);
   103     location.setLatitude(latitude);
   106     location.setLatitude(latitude);
   104     contact.saveDetail(&location);
   107     contact.saveDetail(&location);
   105     bool ret=false;
   108     bool ret = false;
   106     ret=contactManger->saveContact(&contact);
   109     ret = contactManger->saveContact(&contact);
   107     delete contactManger;
   110     delete contactManger;
   108     return ret;
   111     return ret;
   109 }
   112 }
   110 
   113 
   111 // ----------------------------------------------------------------------------
   114 // ----------------------------------------------------------------------------
   112 // CGeocodeUpdate::updateGeocodeToCalenderDB()
   115 // CGeocodeUpdate::updateGeocodeToCalenderDB()
   113 // Geo-cordinate updation to contact db  
   116 // Geo-cordinate updation to contact db  
   114 // ----------------------------------------------------------------------------
   117 // ----------------------------------------------------------------------------
   115 bool GeocodeUpdate::updateGeocodeToCalenderDB(const ulong calEntryId,
   118 bool GeocodeUpdate::updateGeocodeToCalenderDB(const ulong& calEntryId, const double& latitude,
   116         const double latitude, const double longitude)
   119     const double& longitude)
   117 
   120 
   118 {
   121 {
   119     __TRACE_CALLSTACK;
   122     __TRACE_CALLSTACK;
   120     AgendaUtil agendaUtil ;    
   123     bool ret = false;
   121     connect(&agendaUtil , SIGNAL(instanceViewCreationCompleted(int)) ,this ,SLOT(agendautilInstanceCreated(int)));
   124     if (mUtilInstanceCreated) {
   122     QEventLoop loop;
   125         AgendaEntry agendaEntry(mAgendaUtil->fetchById(calEntryId));
   123     connect(this,SIGNAL(eventCompleted()),&loop,SLOT(quit()));
   126         MYLOCLOGSTRING("agenda entry created from calender id .");
   124     loop.exec();
   127         AgendaGeoValue geoValue;
   125     AgendaEntry agendaEntry (agendaUtil.fetchById(calEntryId));
   128         geoValue.setLatLong(latitude, longitude);
   126     MYLOCLOGSTRING("agenda entry created from calender id .");
   129         MYLOCLOGSTRING("latitude and longitude set to  AgendaGeoValue object.");
   127     AgendaGeoValue geoValue;
   130         agendaEntry.setGeoValue(geoValue);
   128     geoValue.setLatLong(latitude,longitude);
   131         ret = mAgendaUtil->updateEntry(agendaEntry);
   129     MYLOCLOGSTRING("latitude and longitude set to  AgendaGeoValue object.");
   132     }    
   130     agendaEntry.setGeoValue(geoValue);
       
   131     bool ret=false;
       
   132     ret=agendaUtil.updateEntry(agendaEntry) ;
       
   133     return ret;
   133     return ret;
   134 }
   134 }
   135 
   135 
       
   136 // ----------------------------------------------------------------------------
       
   137 // CGeocodeUpdate::isGeocodeNotAvailable()
       
   138 // check if geo-cordinate are available for this specific entry id.
       
   139 // return true , for available otherwise false.
       
   140 // ----------------------------------------------------------------------------
       
   141 bool GeocodeUpdate::isGeocodeNotAvailable(const ulong& calEntryId)
       
   142 {
       
   143     __TRACE_CALLSTACK;
       
   144     bool ret = false;
       
   145     if (mUtilInstanceCreated) {
       
   146         AgendaEntry agendaEntry(mAgendaUtil->fetchById(calEntryId));
       
   147         const AgendaGeoValue &geoValue = agendaEntry.geoValue();
       
   148         ret = geoValue.isNull();
       
   149     }
       
   150     return ret;
       
   151 }
       
   152 
       
   153 // ----------------------------------------------------------------------------
       
   154 // CGeocodeUpdate::agendautilInstanceCreated()
       
   155 // call back on agendautil instance creation  
       
   156 // ----------------------------------------------------------------------------
   136 void GeocodeUpdate::agendautilInstanceCreated(int status)
   157 void GeocodeUpdate::agendautilInstanceCreated(int status)
   137 {
   158 {
   138     if (AgendaUtil::NoError == status){
   159     if (AgendaUtil::NoError == status) {
       
   160         mUtilInstanceCreated = true;
   139         emit eventCompleted();
   161         emit eventCompleted();
   140     }
   162     }
   141 }
   163 }
   142 //end of line
   164 //end of line