locationdataharvester/geocodeupdate/src/geocodeupdate.cpp
changeset 30 96df3ab41000
parent 26 f3533f6eae3f
child 31 8db05346071b
equal deleted inserted replaced
26:f3533f6eae3f 30:96df3ab41000
    20 #include <qtcontacts.h>
    20 #include <qtcontacts.h>
    21 #include <cntdef.h>
    21 #include <cntdef.h>
    22 #include <agendautil.h>
    22 #include <agendautil.h>
    23 #include <agendaentry.h>
    23 #include <agendaentry.h>
    24 #include <QString>
    24 #include <QString>
       
    25 #include <QEventLoop>
    25 #include <locationservicedefines.h>
    26 #include <locationservicedefines.h>
    26 
       
    27 #include "geocodeupdate.h"
    27 #include "geocodeupdate.h"
    28 #include "mylocationsdefines.h"
    28 #include "mylocationsdefines.h"
    29 #include "mylocationlogger.h"
    29 #include "mylocationlogger.h"
    30 
    30 
    31 using namespace QTM_NAMESPACE;
    31 using namespace QTM_NAMESPACE;
       
    32 
       
    33 
       
    34 // ----------------------------------------------------------------------------
       
    35 // GeocodeUpdate::GeocodeUpdate()
       
    36 // ----------------------------------------------------------------------------
       
    37 GeocodeUpdate::GeocodeUpdate()
       
    38 {
       
    39     
       
    40 }
       
    41 
       
    42 // ----------------------------------------------------------------------------
       
    43 // GeocodeUpdate::~GeocodeUpdate()
       
    44 // ----------------------------------------------------------------------------
       
    45 GeocodeUpdate::~GeocodeUpdate()
       
    46 {
       
    47     __TRACE_CALLSTACK;
       
    48     
       
    49 }
       
    50 
    32 // ----------------------------------------------------------------------------
    51 // ----------------------------------------------------------------------------
    33 // GeocodeUpdate::createContactdb()
    52 // GeocodeUpdate::createContactdb()
    34 // ----------------------------------------------------------------------------
    53 // ----------------------------------------------------------------------------
    35 EXPORT_C void GeocodeUpdate::createContactdb()
    54 void GeocodeUpdate::createContactdb()
    36 {
    55 {
    37     QContactManager* contactManger = NULL;
    56     QContactManager* contactManger = NULL;
    38     MYLOCLOGSTRING("call to create contactManger object and contactdb as well.");
    57     MYLOCLOGSTRING("call to create contactManger object and contactdb as well.");
    39     contactManger = new QContactManager("symbian");
    58     contactManger = new QContactManager("symbian");
    40     delete contactManger;
    59     delete contactManger;
    42 
    61 
    43 // ----------------------------------------------------------------------------
    62 // ----------------------------------------------------------------------------
    44 // CGeocodeUpdate::updateGeocodeToContactDB()
    63 // CGeocodeUpdate::updateGeocodeToContactDB()
    45 // Geo-cordinate updation to contact db  
    64 // Geo-cordinate updation to contact db  
    46 // ----------------------------------------------------------------------------
    65 // ----------------------------------------------------------------------------
    47 EXPORT_C void GeocodeUpdate::updateGeocodeToContactDB(const quint32 contactId,
    66 bool GeocodeUpdate::updateGeocodeToContactDB(const quint32 contactId,
    48         const int addressType, const double latitude,
    67         const int addressType, const double latitude,
    49         const double longitude)
    68         const double longitude)
    50 
    69 
    51 {
    70 {
    52     __TRACE_CALLSTACK;
    71     __TRACE_CALLSTACK;
    59     QContact contact = contactManger->contact( contactId );
    78     QContact contact = contactManger->contact( contactId );
    60     QContactGeoLocation location;
    79     QContactGeoLocation location;
    61 
    80 
    62     switch (addressType)
    81     switch (addressType)
    63     {
    82     {
    64     case ESourceContactsPref:
    83         case ESourceContactsPref:
    65     {
    84         {
    66         break;
    85             break;
    67     }
    86         }
    68     case ESourceContactsWork:
    87         case ESourceContactsWork:
    69     {
    88         {
    70         location.setContexts(QContactDetail::ContextWork);
    89             location.setContexts(QContactDetail::ContextWork);
    71         break;
    90             break;
    72     }
    91         }
    73     case ESourceContactsHome:
    92         case ESourceContactsHome:
    74     {
    93         {
    75         location.setContexts(QContactDetail::ContextHome);
    94             location.setContexts(QContactDetail::ContextHome);
    76         break;
    95             break;
    77     }
    96         }
    78     default:
    97         default:
    79     {
    98         {
    80         break;
    99             return false;       
    81     }
   100         }
    82     }
   101     }
    83     location.setLongitude(longitude);
   102     location.setLongitude(longitude);
    84     location.setLatitude(latitude);
   103     location.setLatitude(latitude);
    85     contact.saveDetail(&location);
   104     contact.saveDetail(&location);
    86     contactManger->saveContact(&contact);
   105     bool ret=false;
       
   106     ret=contactManger->saveContact(&contact);
    87     delete contactManger;
   107     delete contactManger;
    88 
   108     return ret;
    89 }
   109 }
    90 
   110 
    91 // ----------------------------------------------------------------------------
   111 // ----------------------------------------------------------------------------
    92 // CGeocodeUpdate::updateGeocodeToCalenderDB()
   112 // CGeocodeUpdate::updateGeocodeToCalenderDB()
    93 // Geo-cordinate updation to contact db  
   113 // Geo-cordinate updation to contact db  
    94 // ----------------------------------------------------------------------------
   114 // ----------------------------------------------------------------------------
    95 EXPORT_C void GeocodeUpdate::updateGeocodeToCalenderDB(const ulong calEntryId,
   115 bool GeocodeUpdate::updateGeocodeToCalenderDB(const ulong calEntryId,
    96         const double latitude, const double longitude)
   116         const double latitude, const double longitude)
    97 
   117 
    98 {
   118 {
    99     __TRACE_CALLSTACK;
   119     __TRACE_CALLSTACK;
   100     AgendaUtil agendaUtil;
   120     AgendaUtil agendaUtil ;    
       
   121     connect(&agendaUtil , SIGNAL(instanceViewCreationCompleted(int)) ,this ,SLOT(agendautilInstanceCreated(int)));
       
   122     QEventLoop loop;
       
   123     connect(this,SIGNAL(eventCompleted()),&loop,SLOT(quit()));
       
   124     loop.exec();
   101     AgendaEntry agendaEntry (agendaUtil.fetchById(calEntryId));
   125     AgendaEntry agendaEntry (agendaUtil.fetchById(calEntryId));
   102     MYLOCLOGSTRING("agenda entry created from calender id .");
   126     MYLOCLOGSTRING("agenda entry created from calender id .");
   103     AgendaGeoValue geoValue;
   127     AgendaGeoValue geoValue;
   104     geoValue.setLatLong(latitude,longitude);
   128     geoValue.setLatLong(latitude,longitude);
   105     MYLOCLOGSTRING("latitude and longitude set to  AgendaGeoValue object.");
   129     MYLOCLOGSTRING("latitude and longitude set to  AgendaGeoValue object.");
   106     agendaEntry.setGeoValue(geoValue);
   130     agendaEntry.setGeoValue(geoValue);
   107     agendaUtil.updateEntry(agendaEntry);
   131     bool ret=false;
       
   132     ret=agendaUtil.updateEntry(agendaEntry) ;
       
   133     return ret;
       
   134 }
       
   135 
       
   136 void GeocodeUpdate::agendautilInstanceCreated(int status)
       
   137 {
       
   138     if (AgendaUtil::NoError == status){
       
   139         emit eventCompleted();
       
   140     }
   108 }
   141 }
   109 //end of line
   142 //end of line