|
1 /* |
|
2 * Copyright (c) 2006-2007 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: Plugin for Multi-Media information search. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 //SYSTEM INCLUDES |
|
22 #include <e32cmn.h> |
|
23 #include <e32def.h> |
|
24 #include <bautils.h> |
|
25 #include <f32file.h> |
|
26 #include <data_caging_path_literals.hrh> |
|
27 #include <utf.h> |
|
28 #include <barsc.h> |
|
29 #include <apgcli.h> |
|
30 #include <apacmdln.h> |
|
31 #include <AknsConstants.h> |
|
32 #include <apmstd.h> |
|
33 #include <s32mem.h> |
|
34 #include <searchcommon.h> |
|
35 #include <searchcontent.h> |
|
36 #include <searchiconinfo.h> |
|
37 #include <searchdocumentid.h> |
|
38 #include <multimediasearchplugin.mbg> |
|
39 #include <bautils.h> |
|
40 |
|
41 //USER INCLUDES |
|
42 #include "multimediasearchresource.rsg" |
|
43 #include "multimediasearchplugin.h" |
|
44 #include "multimediasearcher.h" |
|
45 #include "multimediasearchplugindefines.h" |
|
46 |
|
47 |
|
48 // --------------------------------------------------- |
|
49 // 1st phase constructor |
|
50 // --------------------------------------------------- |
|
51 // |
|
52 CMutimediaSearchPlugin* CMutimediaSearchPlugin::NewL() |
|
53 { |
|
54 CMutimediaSearchPlugin* self = new ( ELeave ) CMutimediaSearchPlugin(); |
|
55 |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL(); |
|
58 CleanupStack::Pop( self ); |
|
59 |
|
60 return self; |
|
61 } |
|
62 |
|
63 // --------------------------------------------------- |
|
64 // Destructor |
|
65 // --------------------------------------------------- |
|
66 // |
|
67 CMutimediaSearchPlugin::~CMutimediaSearchPlugin() |
|
68 { |
|
69 // Delete the caption buffers |
|
70 delete iImagesCaption; |
|
71 iImagesCaption = NULL; |
|
72 |
|
73 delete iMusicCaption; |
|
74 iMusicCaption = NULL; |
|
75 |
|
76 delete iVideosCaption; |
|
77 iVideosCaption = NULL; |
|
78 } |
|
79 |
|
80 |
|
81 // --------------------------------------------------- |
|
82 // Creates a content searcher and ownership is transfered |
|
83 // to calling function |
|
84 // --------------------------------------------------- |
|
85 // |
|
86 MSearchContentSearcher* CMutimediaSearchPlugin::ContentSearcherL( |
|
87 const RArray<TUid>& aContentIdArray, const CSearchCondition& aCondition,MSearchPluginObserver& aObserver ) |
|
88 { |
|
89 |
|
90 // Parse through the aContentIdArray, Check if there are any of the |
|
91 // multimedia uids (i.e. music,images,videos) |
|
92 |
|
93 for( TInt j = 0; j < aContentIdArray.Count(); j++ ) |
|
94 { |
|
95 |
|
96 if( (aContentIdArray[j].iUid == KSearchCClassImagesUid.iUid )) |
|
97 { |
|
98 // create the iImagesSearcher |
|
99 iImagesSearcher = NULL; |
|
100 iImagesSearcher = CMultimediaSearcher::NewL( aContentIdArray, |
|
101 aCondition, PluginId(),aObserver ); |
|
102 //Set the media type and content class |
|
103 iImagesSearcher->SetMediaType(ECLFMediaTypeImage); |
|
104 iImagesSearcher->SetContentClassUid(KSearchCClassImagesUid); |
|
105 return iImagesSearcher; |
|
106 } |
|
107 else if( (aContentIdArray[j].iUid == KSearchCClassMusicUid.iUid )) |
|
108 { |
|
109 // create the iMusicSearcher |
|
110 iMusicSearcher = NULL; |
|
111 iMusicSearcher = CMultimediaSearcher::NewL( aContentIdArray, |
|
112 aCondition, PluginId(),aObserver ); |
|
113 //Set the media type and content class |
|
114 iMusicSearcher->SetMediaType(ECLFMediaTypeMusic); |
|
115 iMusicSearcher->SetContentClassUid(KSearchCClassMusicUid); |
|
116 |
|
117 return iMusicSearcher; |
|
118 } |
|
119 else if((aContentIdArray[j].iUid == KSearchCClassVideosUid.iUid )) |
|
120 { |
|
121 // create the iVideoSearcher |
|
122 iVideoSearcher = NULL; |
|
123 iVideoSearcher = CMultimediaSearcher::NewL( aContentIdArray, |
|
124 aCondition, PluginId(),aObserver ); |
|
125 //Set the media type and content class |
|
126 iVideoSearcher->SetMediaType(ECLFMediaTypeVideo); |
|
127 iVideoSearcher->SetContentClassUid(KSearchCClassVideosUid); |
|
128 return iVideoSearcher; |
|
129 } |
|
130 } |
|
131 |
|
132 //Return NULL in case aContentIdArray does not have any of multimedia uids |
|
133 return NULL; |
|
134 } |
|
135 |
|
136 // --------------------------------------------------- |
|
137 // Gets supported contents |
|
138 // --------------------------------------------------- |
|
139 // |
|
140 void CMutimediaSearchPlugin::GetSupportedContentL( |
|
141 RPointerArray<CSearchContent>& aContent ) |
|
142 { |
|
143 //Add the Images,Videos and Music Content classes |
|
144 AddSearchContentClassL(KSearchCClassImagesUid,aContent); |
|
145 AddSearchContentClassL(KSearchCClassMusicUid,aContent); |
|
146 AddSearchContentClassL(KSearchCClassVideosUid,aContent); |
|
147 |
|
148 } |
|
149 |
|
150 |
|
151 // --------------------------------------------------- |
|
152 // Returns if the given content is supported or not |
|
153 // --------------------------------------------------- |
|
154 // |
|
155 TBool CMutimediaSearchPlugin::IsSupportedContent( TUid aContentId ) |
|
156 { |
|
157 if( (KSearchCClassImagesUid.iUid == aContentId.iUid ) || |
|
158 (KSearchCClassMusicUid.iUid == aContentId.iUid) || |
|
159 (KSearchCClassVideosUid.iUid == aContentId.iUid) |
|
160 ) |
|
161 { |
|
162 //Supported, so return true |
|
163 return ETrue; |
|
164 } |
|
165 |
|
166 return EFalse; |
|
167 } |
|
168 |
|
169 |
|
170 // --------------------------------------------------- |
|
171 // Launches the application corresponding to documentId |
|
172 // --------------------------------------------------- |
|
173 // |
|
174 void CMutimediaSearchPlugin::LaunchApplicationL( const TDesC8& aLaunchInfo ) |
|
175 { |
|
176 |
|
177 RFs fs; |
|
178 User::LeaveIfError( fs.Connect() ); |
|
179 TEntry fileEntry; |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 HBufC *temp = HBufC::NewL(KMaxFileName) ; |
|
185 TPtr docIdPtr = temp->Des(); |
|
186 CnvUtfConverter::ConvertToUnicodeFromUtf8( docIdPtr,aLaunchInfo) ; |
|
187 |
|
188 |
|
189 |
|
190 fs.Entry( *temp, fileEntry ); |
|
191 TBool testPath = BaflUtils::FileExists( fs, *temp ); |
|
192 if ( !testPath ) |
|
193 { |
|
194 User::Leave( KErrNotFound ); |
|
195 } |
|
196 fs.Close(); |
|
197 |
|
198 RApaLsSession session; |
|
199 if(session.Connect() != KErrNone) |
|
200 { |
|
201 return; |
|
202 } |
|
203 // Gets the UID and MIME type for the given file name. |
|
204 TUid uid; |
|
205 TDataType dataType; |
|
206 TInt err = session.AppForDocument(*temp, uid, dataType); |
|
207 |
|
208 // Runs the default application using the MIME type, dataType. |
|
209 // You can also use the UID to run the application. |
|
210 // If the Type is unrecognized dont do anything |
|
211 if( KErrNone == err && uid.iUid ) |
|
212 { |
|
213 TThreadId threadId; |
|
214 User::LeaveIfError( session.StartDocument(*temp, dataType, threadId) ); |
|
215 } |
|
216 |
|
217 session.Close(); |
|
218 |
|
219 delete temp; |
|
220 temp = NULL; |
|
221 |
|
222 } |
|
223 |
|
224 |
|
225 // --------------------------------------------------- |
|
226 // Constructor |
|
227 // --------------------------------------------------- |
|
228 // |
|
229 CMutimediaSearchPlugin::CMutimediaSearchPlugin( ) |
|
230 { |
|
231 |
|
232 |
|
233 } |
|
234 |
|
235 |
|
236 // --------------------------------------------------- |
|
237 // 2nd phase constructor |
|
238 // --------------------------------------------------- |
|
239 // |
|
240 void CMutimediaSearchPlugin::ConstructL() |
|
241 { |
|
242 // Create the resource file details |
|
243 RResourceFile resourceFile; |
|
244 HBufC* resourceFileName = HBufC::NewL( KMaxFileName ); |
|
245 TPtr resourceFileNamePtr = resourceFileName->Des(); |
|
246 TPtrC driveLetter = TParsePtrC( RProcess().FileName() ).Drive(); |
|
247 |
|
248 RFs fsSession; |
|
249 User::LeaveIfError( fsSession.Connect() ); |
|
250 |
|
251 //Read resource file |
|
252 resourceFileNamePtr.Copy( driveLetter ); |
|
253 resourceFileNamePtr.Append( KDC_ECOM_RESOURCE_DIR ); |
|
254 resourceFileNamePtr.Append( KResoureFileName ); |
|
255 |
|
256 CleanupClosePushL( resourceFile ); |
|
257 TFileName fileName = resourceFileName->Des(); |
|
258 BaflUtils::NearestLanguageFile( fsSession,fileName ); |
|
259 resourceFile.OpenL(fsSession, fileName ); |
|
260 resourceFile.ConfirmSignatureL(0); |
|
261 |
|
262 // Fetch the caption "Images" |
|
263 { |
|
264 |
|
265 HBufC8* readBuffer = resourceFile.AllocReadLC( R_QTN_SEARCH_TYPES_IMAGES ); |
|
266 |
|
267 const TPtrC16 ptrReadBuffer( ( TText16*) readBuffer->Ptr(), |
|
268 ( readBuffer->Length()+1 )>>1 ); |
|
269 |
|
270 iImagesCaption = ptrReadBuffer.AllocL() ; |
|
271 |
|
272 CleanupStack::PopAndDestroy( readBuffer ); |
|
273 |
|
274 } |
|
275 |
|
276 // Fetch the caption "Music" |
|
277 { |
|
278 |
|
279 HBufC8* readBuffer = resourceFile.AllocReadLC( R_QTN_SEARCH_TYPES_MUSIC ); |
|
280 |
|
281 const TPtrC16 ptrReadBuffer( ( TText16*) readBuffer->Ptr(), |
|
282 ( readBuffer->Length()+1 )>>1 ); |
|
283 |
|
284 iMusicCaption = ptrReadBuffer.AllocL(); |
|
285 |
|
286 CleanupStack::PopAndDestroy( readBuffer ); |
|
287 |
|
288 } |
|
289 // Fetch the caption "Videos" |
|
290 { |
|
291 |
|
292 HBufC8* readBuffer = resourceFile.AllocReadLC( R_QTN_SEARCH_TYPES_VIDEOS ); |
|
293 |
|
294 const TPtrC16 ptrReadBuffer( ( TText16*) readBuffer->Ptr(), |
|
295 ( readBuffer->Length()+1 )>>1 ); |
|
296 |
|
297 iVideosCaption = ptrReadBuffer.AllocL() ; |
|
298 |
|
299 CleanupStack::PopAndDestroy( readBuffer ); |
|
300 |
|
301 } |
|
302 |
|
303 CleanupStack::Pop( ); |
|
304 resourceFile.Close(); |
|
305 delete resourceFileName; |
|
306 resourceFileName = NULL; |
|
307 fsSession.Close(); |
|
308 } |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 // --------------------------------------------------- |
|
315 // Adds the Content Class depending on the input Uid parameter |
|
316 // --------------------------------------------------- |
|
317 // |
|
318 void CMutimediaSearchPlugin::AddSearchContentClassL(const TUid aSearchClassUid, |
|
319 RPointerArray<CSearchContent>& aContent ) |
|
320 { |
|
321 |
|
322 |
|
323 CSearchContent* content = NULL; |
|
324 CSearchIconInfo* icon = NULL; |
|
325 |
|
326 content = CSearchContent::NewL( CSearchContent::ETypeContentClass ); |
|
327 |
|
328 CleanupStack::PushL( content ); |
|
329 content->SetContentId( aSearchClassUid ); |
|
330 content->SetSubContentId( 0 ); |
|
331 content->SetPluginId( this->PluginId() ); |
|
332 |
|
333 _LIT( KFilesMifFileName, "multimediasearchplugin.mif" ); |
|
334 TPtrC driveLetter = TParsePtrC( RProcess().FileName() ).Drive(); |
|
335 |
|
336 TFileName mifFileName( driveLetter ); |
|
337 mifFileName.Append( KDC_APP_BITMAP_DIR ); |
|
338 mifFileName.Append( KFilesMifFileName ); |
|
339 icon = CSearchIconInfo::NewL(); |
|
340 |
|
341 //Set the correct SearchType, prop_file_images_sub and mask |
|
342 TInt32 EMbmMultimediasearchplugin_Type(0); |
|
343 TInt32 EMbmMultimediasearchplugin_Type_Mask(0); |
|
344 if(aSearchClassUid.iUid == KSearchCClassImagesUid.iUid ) |
|
345 { |
|
346 // Images content class |
|
347 content->SetCaptionL( *iImagesCaption ); |
|
348 EMbmMultimediasearchplugin_Type = |
|
349 EMbmMultimediasearchpluginQgn_prop_file_images_sub; |
|
350 EMbmMultimediasearchplugin_Type_Mask = |
|
351 EMbmMultimediasearchpluginQgn_prop_file_images_sub_mask; |
|
352 } |
|
353 else if(aSearchClassUid.iUid == KSearchCClassMusicUid.iUid) |
|
354 { |
|
355 // Music content class |
|
356 content->SetCaptionL( *iMusicCaption ); |
|
357 EMbmMultimediasearchplugin_Type = EMbmMultimediasearchpluginQgn_prop_file_music_sub; |
|
358 EMbmMultimediasearchplugin_Type_Mask = EMbmMultimediasearchpluginQgn_prop_file_music_sub_mask; |
|
359 } |
|
360 else if(aSearchClassUid.iUid == KSearchCClassVideosUid.iUid) |
|
361 { |
|
362 // Videos content class |
|
363 content->SetCaptionL( *iVideosCaption ); |
|
364 EMbmMultimediasearchplugin_Type = EMbmMultimediasearchpluginQgn_prop_file_video; |
|
365 EMbmMultimediasearchplugin_Type_Mask = EMbmMultimediasearchpluginQgn_prop_file_video_mask; |
|
366 } |
|
367 |
|
368 |
|
369 // Handle Icon related operations |
|
370 CleanupStack::PushL( icon ); |
|
371 |
|
372 icon->SetSkinId( KAknsIIDQgnPropFmgrFileApps ); |
|
373 |
|
374 icon->SetIconFileL( mifFileName ); |
|
375 |
|
376 icon->SetIconIndex( EMbmMultimediasearchplugin_Type ); |
|
377 |
|
378 icon->SetIconMaskIndex( EMbmMultimediasearchplugin_Type_Mask ); |
|
379 CleanupStack::Pop( icon ); |
|
380 |
|
381 content->SetIconInfo( icon ); |
|
382 |
|
383 aContent.Append( content ); |
|
384 |
|
385 CleanupStack::Pop( content ); |
|
386 |
|
387 } |
|
388 |
|
389 |
|
390 //End of file |