|
1 /* |
|
2 * Copyright (c) 2009 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: A class for creating country and city tags for media files |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "ctagcreator.h" |
|
19 #include "locationmanagerdebug.h" |
|
20 |
|
21 #include "mdccommon.h" |
|
22 #include "mdeobjectdef.h" |
|
23 #include "mdepropertydef.h" |
|
24 #include "mderelation.h" |
|
25 #include "mdequery.h" |
|
26 #include "mdeconstants.h" |
|
27 |
|
28 using namespace MdeConstants; |
|
29 |
|
30 _LIT ( KCountry, "country:"); // country:finland |
|
31 _LIT ( KCity, "city:"); // city:helsinki|country:finland |
|
32 _LIT ( KSeparator, "|" ); // Separator for city tag. Separate city and country. |
|
33 |
|
34 // -------------------------------------------------------------------------- |
|
35 // CTagCreator::NewL |
|
36 // -------------------------------------------------------------------------- |
|
37 // |
|
38 EXPORT_C CTagCreator* CTagCreator::NewL( ) |
|
39 { |
|
40 LOG( "CTagCreator::NewL(), begin" ); |
|
41 CTagCreator* self = new (ELeave) CTagCreator( ); |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL(); |
|
44 CleanupStack::Pop( self ); |
|
45 LOG( "CTagCreator::NewL(), end" ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // -------------------------------------------------------------------------- |
|
50 // CTagCreator::CTagCreator |
|
51 // -------------------------------------------------------------------------- |
|
52 // |
|
53 CTagCreator::CTagCreator( ) |
|
54 { |
|
55 |
|
56 } |
|
57 |
|
58 // -------------------------------------------------------------------------- |
|
59 // CTagCreator::ConstructL |
|
60 // -------------------------------------------------------------------------- |
|
61 // |
|
62 void CTagCreator::ConstructL() |
|
63 { |
|
64 |
|
65 } |
|
66 |
|
67 // -------------------------------------------------------------------------- |
|
68 // CTagCreator::~CTagCreator |
|
69 // -------------------------------------------------------------------------- |
|
70 // |
|
71 CTagCreator::~CTagCreator() |
|
72 { |
|
73 |
|
74 } |
|
75 |
|
76 // -------------------------------------------------------------------------- |
|
77 // CTagCreator::SetMdeSession() |
|
78 // -------------------------------------------------------------------------- |
|
79 // |
|
80 EXPORT_C void CTagCreator::SetSession(CMdESession* aSession) |
|
81 { |
|
82 iMdeSession = aSession; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CTagCreator::CreateTagForCountryL() |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 void CTagCreator::CreateTagForCountryL( const TPtrC& aCountry, |
|
90 TItemId& aCountryTagId ) |
|
91 { |
|
92 LOG( "CTagCreator::CreateTagForCountryL - begin" ); |
|
93 |
|
94 // Crete new string for uri, -> country:India. |
|
95 TUint totalLength = ( aCountry.Length() + KCountry().Length() ); |
|
96 HBufC* buf = HBufC::NewLC( totalLength ); |
|
97 TPtr uriPtr = buf->Des(); |
|
98 _LIT(KCountryUriFormat, "%S%S"); |
|
99 uriPtr.Format(KCountryUriFormat, &(KCountry()), &aCountry); |
|
100 |
|
101 // Check if there is allready tag for current country. |
|
102 aCountryTagId = TagExistsL( uriPtr ); |
|
103 |
|
104 if( !aCountryTagId ) |
|
105 { |
|
106 // No tag, create tag for country. |
|
107 aCountryTagId = CreateTagL( aCountry, uriPtr, MdeConstants::Tag::ESystemDefineCountryTags); |
|
108 } |
|
109 |
|
110 CleanupStack::PopAndDestroy( buf ); |
|
111 |
|
112 LOG( "CTagCreator::CreateTagForCountryL - end" ); |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CTagCreator::CreateTagForCityL() |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void CTagCreator::CreateTagForCityL( const TPtrC& aCountry, const TPtrC& aCity, TItemId& aCityTagId ) |
|
120 { |
|
121 LOG( "CTagCreator::CreateTagForCityL - begin" ); |
|
122 |
|
123 // Crete new string for uri, -> city:bangalore|country:india |
|
124 TUint totalLength = ( aCity.Length() + KCity.iTypeLength + |
|
125 aCountry.Length() + KCountry.iTypeLength + KSeparator.iTypeLength ); |
|
126 |
|
127 HBufC* buf = HBufC::NewLC( totalLength ); |
|
128 TPtr uriPtr = buf->Des(); |
|
129 _LIT(KCityCountryUriFormat, "%S%S%S%S%S"); |
|
130 uriPtr.Format(KCityCountryUriFormat, |
|
131 &(KCity()), |
|
132 &aCity, |
|
133 &(KSeparator()), |
|
134 &(KCountry()), |
|
135 &aCountry); |
|
136 |
|
137 // Check if there is allready tag for current city. |
|
138 aCityTagId = TagExistsL( uriPtr ); |
|
139 |
|
140 if( !aCityTagId ) |
|
141 { |
|
142 // No tag, create tag for city. |
|
143 aCityTagId = CreateTagL( aCity, uriPtr, MdeConstants::Tag::ESystemDefineCityTags); |
|
144 } |
|
145 |
|
146 CleanupStack::PopAndDestroy( buf ); |
|
147 |
|
148 LOG( "CTagCreator::CreateTagForCityL - end" ); |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // CTagCreator::CreateTagL |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 TUint32 CTagCreator::CreateTagL( const TPtrC& aTitle, |
|
156 const TPtrC& aUri, |
|
157 MdeConstants::Tag::TTagType aTagType) |
|
158 { |
|
159 LOG( "CTagCreator::CreateTagL - begin" ); |
|
160 |
|
161 CMdENamespaceDef& defaultNamespace = iMdeSession->GetDefaultNamespaceDefL(); |
|
162 // Create tag object. |
|
163 CMdEObjectDef& tagObjectDef = defaultNamespace.GetObjectDefL( Tag::KTagObject ); |
|
164 |
|
165 CMdEObject* tagObject = NULL; |
|
166 tagObject = iMdeSession->NewObjectLC( tagObjectDef, aUri ); |
|
167 |
|
168 // Type defs. |
|
169 CMdEPropertyDef& creationDef = tagObjectDef.GetPropertyDefL( |
|
170 Object::KCreationDateProperty ); |
|
171 CMdEPropertyDef& modifiedDef = tagObjectDef.GetPropertyDefL( |
|
172 Object::KLastModifiedDateProperty ); |
|
173 CMdEPropertyDef& sizeDef = tagObjectDef.GetPropertyDefL( |
|
174 Object::KSizeProperty ); |
|
175 CMdEPropertyDef& itemTypeDef = tagObjectDef.GetPropertyDefL( |
|
176 Object::KItemTypeProperty ); |
|
177 CMdEPropertyDef& titleDef = tagObjectDef.GetPropertyDefL( |
|
178 Object::KTitleProperty ); |
|
179 |
|
180 // Set propertys. |
|
181 TTime universalTime; |
|
182 universalTime.UniversalTime(); |
|
183 |
|
184 // Creation time. |
|
185 tagObject->AddTimePropertyL( creationDef, universalTime ); |
|
186 |
|
187 // Modification time. |
|
188 tagObject->AddTimePropertyL( modifiedDef, universalTime ); |
|
189 |
|
190 // Size |
|
191 tagObject->AddUint32PropertyL( sizeDef, aTagType); |
|
192 |
|
193 // ItemType. |
|
194 tagObject->AddTextPropertyL( itemTypeDef, Tag::KTagItemType ); |
|
195 |
|
196 // Title, for country. |
|
197 if ( aTitle.Length() > 0 ) |
|
198 { |
|
199 tagObject->AddTextPropertyL( titleDef, aTitle ); // Add title |
|
200 } |
|
201 |
|
202 // Finally add to database. |
|
203 TItemId itemId = iMdeSession->AddObjectL( *tagObject ); |
|
204 |
|
205 CleanupStack::PopAndDestroy( tagObject ); |
|
206 |
|
207 LOG( "CTagCreator::CreateTagL - end" ); |
|
208 |
|
209 return itemId; |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // CTagCreator::TagExistsL |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 TUint32 CTagCreator::TagExistsL( const TPtrC& aUri ) |
|
217 { |
|
218 LOG( "CTagCreator::TagExistsL - begin" ); |
|
219 |
|
220 CMdEObject* mdeObject = NULL; |
|
221 mdeObject = iMdeSession->GetObjectL( aUri ) ; // Just to find out if it exists. |
|
222 |
|
223 if( mdeObject ) |
|
224 { |
|
225 LOG( "CTagCreator::TagExistsL - returning object id" ); |
|
226 return mdeObject->Id(); |
|
227 } |
|
228 else |
|
229 { |
|
230 LOG( "CTagCreator::TagExistsL - No object, return 0" ); |
|
231 return 0; |
|
232 } |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------------------------- |
|
236 // CGeoTagger::AttachTagsL |
|
237 // Create relationship to country and city tag |
|
238 // --------------------------------------------------------------------------- |
|
239 // |
|
240 EXPORT_C void CTagCreator::AttachTagsL( const TUint32 aObjectId, const TItemId aCountryTagId, |
|
241 const TItemId aCityTagId ) |
|
242 { |
|
243 LOG( "CGeoTagger::AttachTagsL" ); |
|
244 CMdENamespaceDef& defaultNamespace = iMdeSession->GetDefaultNamespaceDefL(); |
|
245 // contains relation definition |
|
246 CMdERelationDef& containsRelDef = defaultNamespace.GetRelationDefL( |
|
247 Relations::KContains ); |
|
248 |
|
249 // Create relation between country tag and media object (image/video). |
|
250 CMdERelation* relationObject = NULL; |
|
251 if ( aCountryTagId ) |
|
252 { |
|
253 relationObject = iMdeSession->NewRelationLC ( containsRelDef, |
|
254 aObjectId, aCountryTagId, 0 ); |
|
255 |
|
256 if ( !relationObject ) |
|
257 { |
|
258 LOG( "CGeoTagger::AttachTagsL - Couldn't create relation object!" ); |
|
259 User::Leave ( KErrBadHandle ); |
|
260 } |
|
261 |
|
262 iMdeSession->AddRelationL( *relationObject ); |
|
263 |
|
264 CleanupStack::PopAndDestroy( relationObject ); |
|
265 } |
|
266 |
|
267 // Create relation between city tag and media object (image/video). |
|
268 if ( aCityTagId ) |
|
269 { |
|
270 relationObject = iMdeSession->NewRelationLC ( containsRelDef, |
|
271 aObjectId, aCityTagId, 0 ); |
|
272 |
|
273 if ( !relationObject) |
|
274 { |
|
275 LOG( "CGeoTagger::AttachTagsL - Couldn't create relation object!" ); |
|
276 User::Leave ( KErrBadHandle ); |
|
277 } |
|
278 |
|
279 iMdeSession->AddRelationL( *relationObject ); |
|
280 |
|
281 CleanupStack::PopAndDestroy( relationObject ); |
|
282 } |
|
283 |
|
284 LOG( "CGeoTagger::AttachTagsL - end" ); |
|
285 } |
|
286 |
|
287 // --------------------------------------------------------------------------- |
|
288 // CGeoTagger::CreateLocationTagsL |
|
289 // Create country and city tags |
|
290 // --------------------------------------------------------------------------- |
|
291 // |
|
292 EXPORT_C void CTagCreator::CreateLocationTagsL( const TPtrC& aCountry, TItemId& aCountryTagId, |
|
293 const TPtrC& aCity, TItemId& aCityTagId) |
|
294 { |
|
295 LOG( "CGeoTagger::CreateLocationTagsL" ); |
|
296 if( aCountry.Length() > 0 ) |
|
297 { |
|
298 CreateTagForCountryL( aCountry, aCountryTagId ); |
|
299 } |
|
300 |
|
301 if( aCity.Length() > 0 ) |
|
302 { |
|
303 CreateTagForCityL( aCountry, aCity, aCityTagId ); |
|
304 } |
|
305 } |
|
306 |
|
307 // End of file |