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