|
1 /* |
|
2 * Copyright (c) 2008-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: Tag collection plugin implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "glxcollectionplugintags.h" |
|
23 #include "glxcollectionplugintags.hrh" |
|
24 |
|
25 |
|
26 #include <mpxmediageneraldefs.h> //KMPXMediaIdGeneral |
|
27 #include <mpxmediacontainerdefs.h> //Attributes for KMPXMediaIdContainer |
|
28 #include <StringLoader.h> |
|
29 #include <glxplugintags.rsg> |
|
30 #include <mglxdatasource.h> //MGlxDataSource |
|
31 #include <glxlog.h> //For Logging |
|
32 #include <glxtracer.h> |
|
33 |
|
34 _LIT(KResourceFile, "z:glxplugintags.rsc"); |
|
35 /** |
|
36 * @internal reviewed 14/06/2007 by Alex Birkett |
|
37 */ |
|
38 |
|
39 // ---------------------------------------------------------------------------- |
|
40 // Two-Phased Constructor |
|
41 // ---------------------------------------------------------------------------- |
|
42 |
|
43 CGlxCollectionPluginTags* CGlxCollectionPluginTags::NewL(TAny* aObs) |
|
44 { |
|
45 TRACER("CGlxCollectionPluginTags::NewL"); |
|
46 |
|
47 CGlxCollectionPluginTags* self = new (ELeave) CGlxCollectionPluginTags( |
|
48 static_cast<MMPXCollectionPluginObserver*>(aObs)); |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop(self); |
|
52 return self; |
|
53 } |
|
54 |
|
55 |
|
56 // ---------------------------------------------------------------------------- |
|
57 // Destructor |
|
58 // ---------------------------------------------------------------------------- |
|
59 // |
|
60 CGlxCollectionPluginTags::~CGlxCollectionPluginTags() |
|
61 { |
|
62 //Do Nothing |
|
63 } |
|
64 |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // Constructor |
|
68 // ---------------------------------------------------------------------------- |
|
69 void CGlxCollectionPluginTags::ConstructL() |
|
70 { |
|
71 TRACER("CGlxCollectionPluginTags::ConstructL"); |
|
72 |
|
73 // iDataSource - @owner is CGlxCollectionPluginBase |
|
74 iDataSource = MGlxDataSource::OpenDataSourceL(KGlxDefaultDataSourceUid, *this); |
|
75 } |
|
76 |
|
77 |
|
78 // ---------------------------------------------------------------------------- |
|
79 // Constructor |
|
80 // ---------------------------------------------------------------------------- |
|
81 |
|
82 CGlxCollectionPluginTags::CGlxCollectionPluginTags( |
|
83 MMPXCollectionPluginObserver* aObs) |
|
84 { |
|
85 iObs = aObs; |
|
86 } |
|
87 |
|
88 |
|
89 // ---------------------------------------------------------------------------- |
|
90 // Add Additional attributes |
|
91 // ---------------------------------------------------------------------------- |
|
92 |
|
93 void CGlxCollectionPluginTags::CpiAttributeAdditionalAttributes( |
|
94 const TMPXAttribute& aCpiAttribute, RArray<TMPXAttribute>& aAttributeArray) |
|
95 { |
|
96 TRACER("CGlxCollectionPluginTags::CpiAttributeAdditionalAttributes"); |
|
97 // Only need to process KGlxMediaCollectionPluginSpecificSubTitle here as all |
|
98 // the others are reading straight from resource files |
|
99 // KGlxMediaCollectionPluginSpecificSubTitle requires a usage count |
|
100 if (aCpiAttribute == KGlxMediaCollectionPluginSpecificSubTitle) |
|
101 { |
|
102 // need to add the usage count. but check first if it is already present |
|
103 TInt attrCount = aAttributeArray.Count(); |
|
104 TBool found = EFalse; |
|
105 |
|
106 GLX_DEBUG1("CGlxCollectionPluginTags::CpiAttributeAdditionalAttributes-AttributesCount"); |
|
107 |
|
108 for ( TInt index = 0 ; index < attrCount ; index++) |
|
109 { |
|
110 if (aAttributeArray[index] == KMPXMediaGeneralCount) |
|
111 { |
|
112 found = ETrue; |
|
113 break; |
|
114 } |
|
115 } |
|
116 |
|
117 if (!found) |
|
118 { |
|
119 aAttributeArray.Append(KMPXMediaGeneralCount); |
|
120 } |
|
121 } |
|
122 } |
|
123 |
|
124 |
|
125 // ---------------------------------------------------------------------------- |
|
126 // Modify the response |
|
127 // ---------------------------------------------------------------------------- |
|
128 |
|
129 void CGlxCollectionPluginTags::HandleCpiAttributeResponseL(CMPXMedia* aResponse, |
|
130 TArray<TMPXAttribute> aCpiAttributes, TArray<TGlxMediaId> aMediaIds) |
|
131 { |
|
132 TRACER("CGlxCollectionPluginTags::HandleCpiAttributeResponseL"); |
|
133 const TInt mediaIdCount = aMediaIds.Count(); |
|
134 |
|
135 switch (mediaIdCount) |
|
136 { |
|
137 case 0: |
|
138 User::Leave(KErrNotSupported); |
|
139 break; |
|
140 |
|
141 case 1: |
|
142 GLX_LOG_INFO("CGlxCollectionPluginTags::HandleCpiAttributeResponseL-MediaID"); |
|
143 |
|
144 HandleCpiAttributeResponseL(aResponse, aCpiAttributes, aMediaIds[0]); |
|
145 break; |
|
146 |
|
147 |
|
148 default: |
|
149 { |
|
150 // We have an array of CMPXMedia items |
|
151 |
|
152 if (TGlxMediaId(KGlxCollectionRootId) == aMediaIds[0]) |
|
153 { |
|
154 User::Leave(KErrNotSupported); |
|
155 } |
|
156 |
|
157 CMPXMediaArray* mediaArray = aResponse->ValueCObjectL<CMPXMediaArray>(KMPXMediaArrayContents); |
|
158 CleanupStack::PushL(mediaArray); |
|
159 |
|
160 const TInt arrayCount = mediaArray->Count(); |
|
161 |
|
162 // Sanity check |
|
163 if (arrayCount != mediaIdCount) |
|
164 { |
|
165 User::Leave(KErrArgument); |
|
166 } |
|
167 |
|
168 for (TInt index = 0; index < arrayCount; index++) |
|
169 { |
|
170 HandleCpiAttributeResponseL((*mediaArray)[index], aCpiAttributes, |
|
171 aMediaIds[index]); |
|
172 } |
|
173 |
|
174 /// @todo - Can we reset a value. Does it overwrite the original or does it leak? Must test |
|
175 aResponse->SetCObjectValueL(KMPXMediaArrayContents, mediaArray); |
|
176 CleanupStack::PopAndDestroy(mediaArray); |
|
177 } |
|
178 break; |
|
179 } |
|
180 } |
|
181 |
|
182 |
|
183 // ---------------------------------------------------------------------------- |
|
184 // Modify the response |
|
185 // ---------------------------------------------------------------------------- |
|
186 |
|
187 void CGlxCollectionPluginTags::HandleCpiAttributeResponseL(CMPXMedia* aResponse, |
|
188 TArray<TMPXAttribute> aCpiAttributes, TGlxMediaId aMediaId) |
|
189 { |
|
190 |
|
191 TRACER("CGlxCollectionPluginTags::HandleCpiAttributeResponseL-Enter"); |
|
192 |
|
193 const TInt attribCount = aCpiAttributes.Count(); |
|
194 |
|
195 GLX_LOG_INFO("CGlxCollectionPluginTags::HandleCpiAttributeResponseL-Attributes created"); |
|
196 |
|
197 for (TInt index = 0; index < attribCount ; index++) |
|
198 { |
|
199 const TMPXAttribute attr = aCpiAttributes[index]; |
|
200 |
|
201 if (attr == KGlxMediaCollectionPluginSpecificSubTitle) |
|
202 { |
|
203 GLX_LOG_INFO("CGlxCollectionPluginTags::HandleCpiAttributeResponseL-Subtitle"); |
|
204 |
|
205 if (!aResponse->IsSupported(KMPXMediaGeneralCount)) |
|
206 { |
|
207 User::Leave(KErrNotSupported); |
|
208 } |
|
209 else |
|
210 { |
|
211 TInt usageCount = aResponse->ValueTObjectL<TInt>(KMPXMediaGeneralCount); |
|
212 HBufC* tempTitle = NULL; |
|
213 |
|
214 if (TGlxMediaId(KGlxCollectionRootId) == aMediaId) |
|
215 { |
|
216 if(0 == usageCount) |
|
217 { |
|
218 tempTitle = LoadLocalizedStringLC(KResourceFile, |
|
219 R_TAG_SUB_TITLE_NO_ITEMS); |
|
220 // Set the title in the response. |
|
221 aResponse->SetTextValueL(attr, *tempTitle); |
|
222 CleanupStack::PopAndDestroy(tempTitle); |
|
223 continue; |
|
224 } |
|
225 else if (1 == usageCount) |
|
226 { |
|
227 tempTitle = LoadLocalizedStringLC(KResourceFile, |
|
228 R_TAG_SUB_TITLE_SINGLE); |
|
229 aResponse->SetTextValueL(attr, *tempTitle); |
|
230 CleanupStack::PopAndDestroy(tempTitle); |
|
231 continue; |
|
232 } |
|
233 else |
|
234 { |
|
235 tempTitle = LoadLocalizedStringLC(KResourceFile, |
|
236 R_TAG_SUB_TITLE_MULTI); |
|
237 } |
|
238 } |
|
239 else |
|
240 { |
|
241 if(0 == usageCount) |
|
242 { |
|
243 tempTitle = LoadLocalizedStringLC(KResourceFile, |
|
244 R_TAG_SUB_TITLE_NO_ITEMS); |
|
245 // Set the title in the response. |
|
246 aResponse->SetTextValueL(attr, *tempTitle); |
|
247 CleanupStack::PopAndDestroy(tempTitle); |
|
248 continue; |
|
249 } |
|
250 else if (1 == usageCount) |
|
251 { |
|
252 tempTitle = LoadLocalizedStringLC(KResourceFile, |
|
253 R_TAG_ITEM_SUB_TITLE_SINGLE); |
|
254 aResponse->SetTextValueL(attr, *tempTitle); |
|
255 CleanupStack::PopAndDestroy(tempTitle); |
|
256 continue; |
|
257 } |
|
258 else |
|
259 { |
|
260 tempTitle = LoadLocalizedStringLC(KResourceFile, |
|
261 R_TAG_ITEM_SUB_TITLE_MULTI); |
|
262 } |
|
263 } |
|
264 TPtr formatString = tempTitle->Des(); |
|
265 |
|
266 // Now create a buffer that will contain the result. needs to be length |
|
267 //of format string plus a few extra for the number |
|
268 HBufC* title = HBufC::NewLC(formatString.Length() + 10); |
|
269 TPtr ptr = title->Des(); |
|
270 StringLoader::Format(ptr, formatString, -1, usageCount); |
|
271 |
|
272 // Set the title in the response. |
|
273 aResponse->SetTextValueL(attr, *title); |
|
274 |
|
275 CleanupStack::PopAndDestroy(title); |
|
276 CleanupStack::PopAndDestroy(tempTitle); |
|
277 } |
|
278 } |
|
279 else if (attr == KGlxMediaCollectionPluginSpecificSelectMediaPopupTitle) |
|
280 { |
|
281 GLX_LOG_INFO("CGlxCollectionPluginTags::HandleCpiAttributeResponseL-Popup Title"); |
|
282 |
|
283 HBufC* title = LoadLocalizedStringLC(KResourceFile, R_TAG_POPUP_TITLE); |
|
284 aResponse->SetTextValueL(attr, *title); |
|
285 CleanupStack::PopAndDestroy(title); |
|
286 |
|
287 } |
|
288 else if (attr == KGlxMediaCollectionPluginSpecificNewMediaItemTitle) |
|
289 { |
|
290 GLX_LOG_INFO("CGlxCollectionPluginTags::HandleCpiAttributeResponseL-Mediaitem"); |
|
291 |
|
292 HBufC* title = LoadLocalizedStringLC(KResourceFile, R_TAG_ITEM_TITLE); |
|
293 aResponse->SetTextValueL(attr, *title); |
|
294 CleanupStack::PopAndDestroy(title); |
|
295 |
|
296 } |
|
297 |
|
298 else if (attr == KGlxMediaCollectionPluginSpecificDefaultMediaTitle) |
|
299 { |
|
300 GLX_LOG_INFO("CGlxCollectionPluginTags::HandleCpiAttributeResponseL-Defualt mediatitle"); |
|
301 |
|
302 HBufC* title = LoadLocalizedStringLC(KResourceFile, R_TAG_DEFAULT_TITLE); |
|
303 aResponse->SetTextValueL(attr, *title); |
|
304 CleanupStack::PopAndDestroy(title); |
|
305 |
|
306 } |
|
307 else if (attr == KMPXMediaGeneralTitle) |
|
308 { |
|
309 GLX_LOG_INFO("CGlxCollectionPluginTags::HandleCpiAttributeResponseL-Attr Title"); |
|
310 |
|
311 HBufC* title = LoadLocalizedStringLC(KResourceFile, R_TAG_GENERAL_TITLE); |
|
312 aResponse->SetTextValueL(attr, *title); |
|
313 CleanupStack::PopAndDestroy(title); |
|
314 } |
|
315 } |
|
316 } |
|
317 |
|
318 // ---------------------------------------------------------------------------- |
|
319 // Ignore the Updated Message |
|
320 // ---------------------------------------------------------------------------- |
|
321 TBool CGlxCollectionPluginTags::IsUpdateMessageIgnored(CMPXMessage& /*aMessage*/) |
|
322 { |
|
323 TRACER("CGlxCollectionPluginTags::IsUpdateMessageIgnored"); |
|
324 TBool ignore = EFalse; |
|
325 return ignore; |
|
326 } |
|
327 |
|
328 // ---------------------------------------------------------------------------- |
|
329 // Set the filter Properties |
|
330 // ---------------------------------------------------------------------------- |
|
331 |
|
332 TGlxFilterProperties CGlxCollectionPluginTags::DefaultFilter(TInt aLevel) |
|
333 { |
|
334 TRACER("CGlxCollectionPluginTags::DefaultFilter"); |
|
335 __ASSERT_DEBUG(( (aLevel == KGlxCollectionRootLevel) || (aLevel == KGlxCollectionTagLevel) |
|
336 || (aLevel == KGlxCollectionTagContentsLevel) || (aLevel == KGlxCollectionTagFSContentsLevel)), |
|
337 Panic(EGlxPanicInvalidPathLevel)); |
|
338 TGlxFilterProperties filterProperties; |
|
339 filterProperties.iSortDirection = EGlxFilterSortDirectionAscending; |
|
340 switch(aLevel) |
|
341 { |
|
342 case KGlxCollectionRootLevel: |
|
343 case KGlxCollectionTagLevel: |
|
344 { |
|
345 filterProperties.iMinCount = 1; |
|
346 filterProperties.iSortOrder = EGlxFilterSortOrderAlphabetical; |
|
347 filterProperties.iItemType = EGlxFilterTag; |
|
348 |
|
349 break; |
|
350 } |
|
351 case KGlxCollectionTagContentsLevel: |
|
352 { |
|
353 filterProperties.iSortDirection = EGlxFilterSortDirectionDescending; |
|
354 } |
|
355 case KGlxCollectionTagFSContentsLevel: |
|
356 { |
|
357 filterProperties.iSortOrder = EGlxFilterSortOrderCaptureDate; |
|
358 break; |
|
359 } |
|
360 } |
|
361 return filterProperties; |
|
362 } |
|
363 |
|
364 //End of File |