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