|
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 file names search |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <e32cmn.h> |
|
22 #include <e32def.h> |
|
23 #include <data_caging_path_literals.hrh> |
|
24 #include <utf.h> |
|
25 #include <apgcli.h> |
|
26 #include <aknnotewrappers.h> |
|
27 #include <bautils.h> |
|
28 #include <searchiconinfo.h> |
|
29 #include <searchdocumentid.h> |
|
30 #include <filessearchplugin.mbg> |
|
31 #include <filessearchresource.rsg> |
|
32 #include <bautils.h> |
|
33 |
|
34 #include "filessearchplugindefines.h" |
|
35 #include "filessearchplugin.h" |
|
36 |
|
37 // --------------------------------------------------------------------------------- |
|
38 // CFilesSearchPlugin::NewL() |
|
39 // 1st phase constructor |
|
40 // --------------------------------------------------------------------------------- |
|
41 // |
|
42 CFilesSearchPlugin* CFilesSearchPlugin::NewL() |
|
43 { |
|
44 CFilesSearchPlugin* self = new ( ELeave ) CFilesSearchPlugin(); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------------- |
|
52 // CFilesSearchPlugin::~CFilesSearchPlugin() |
|
53 // destructor |
|
54 // --------------------------------------------------------------------------------- |
|
55 // |
|
56 CFilesSearchPlugin::~CFilesSearchPlugin() |
|
57 { |
|
58 if ( iCaption ) |
|
59 { |
|
60 delete iCaption; |
|
61 iCaption = NULL; |
|
62 } |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------------- |
|
66 // CFilesSearchPlugin::ContentSearcherL() |
|
67 // Creates a content searcher and ownership is transfered to calling function |
|
68 // --------------------------------------------------------------------------------- |
|
69 // |
|
70 MSearchContentSearcher* CFilesSearchPlugin::ContentSearcherL( |
|
71 const RArray<TUid>& aContentIdArray, const CSearchCondition& aCondition , |
|
72 MSearchPluginObserver& aObserver) |
|
73 |
|
74 { |
|
75 |
|
76 for ( TInt j = 0; j < aContentIdArray.Count(); j++ ) |
|
77 { |
|
78 // create the filesearcher |
|
79 if ( ( aContentIdArray[j].iUid == KSearchCClassFilenamesUid.iUid ) ) |
|
80 { |
|
81 iFileSearcher = CFilesSearcher::NewL( |
|
82 aContentIdArray, aCondition, PluginId(),aObserver ); |
|
83 return iFileSearcher; |
|
84 } |
|
85 } |
|
86 return NULL; |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------------- |
|
90 // CFilesSearchPlugin::GetSupportedContentL() |
|
91 // Gets supported contents |
|
92 // --------------------------------------------------------------------------------- |
|
93 // |
|
94 void CFilesSearchPlugin::GetSupportedContentL( |
|
95 RPointerArray<CSearchContent>& aContent ) |
|
96 { |
|
97 CSearchContent* content = NULL; |
|
98 CSearchIconInfo* icon = NULL; |
|
99 |
|
100 content = CSearchContent::NewL( CSearchContent::ETypeContentClass ); |
|
101 |
|
102 CleanupStack::PushL( content ); |
|
103 content->SetContentId( KSearchCClassFilenamesUid ); |
|
104 content->SetSubContentId( 0 ); |
|
105 content->SetPluginId( this->PluginId() ); |
|
106 |
|
107 _LIT( KFilesMifFileName, "filessearchplugin.mif" ); |
|
108 |
|
109 //Read mif file from |
|
110 TPtrC driveLetter = TParsePtrC( RProcess().FileName() ).Drive(); |
|
111 TFileName mifFileName( driveLetter ); |
|
112 mifFileName.Append( KDC_APP_BITMAP_DIR ); |
|
113 mifFileName.Append( KFilesMifFileName ); |
|
114 |
|
115 //Set Icon information |
|
116 icon = CSearchIconInfo::NewL(); |
|
117 CleanupStack::PushL( icon ); |
|
118 icon->SetSkinId( KAknsIIDQgnPropFmgrFileApps ); |
|
119 icon->SetIconFileL( mifFileName ); |
|
120 icon->SetIconIndex( EMbmFilessearchpluginQgn_prop_search_file_names ); |
|
121 icon->SetIconMaskIndex( EMbmFilessearchpluginQgn_prop_search_file_names_mask ); |
|
122 CleanupStack::Pop( icon ); |
|
123 |
|
124 content->SetIconInfo( icon ); |
|
125 |
|
126 //Setting the caption |
|
127 content->SetCaptionL( *iCaption ); |
|
128 |
|
129 aContent.AppendL( content ); |
|
130 CleanupStack::Pop( content ); |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------------- |
|
134 // CFilesSearchPlugin::IsSupportedContent() |
|
135 // Returns if the given content is supported or not |
|
136 // --------------------------------------------------------------------------------- |
|
137 // |
|
138 TBool CFilesSearchPlugin::IsSupportedContent( TUid aContentId ) |
|
139 { |
|
140 if ( KSearchCClassFilenamesUid.iUid == aContentId.iUid ) |
|
141 { |
|
142 return ETrue; |
|
143 } |
|
144 |
|
145 return EFalse; |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------------- |
|
149 // CFilesSearchPlugin::LaunchApplicationL() |
|
150 // Launches the application corresponding to document id |
|
151 // --------------------------------------------------------------------------------- |
|
152 // |
|
153 void CFilesSearchPlugin::LaunchApplicationL(const TDesC8& aLaunchInfo) |
|
154 { |
|
155 RFs fs; |
|
156 User::LeaveIfError( fs.Connect() ); |
|
157 TEntry fileEntry; |
|
158 |
|
159 HBufC *path16 = HBufC::NewL(KMaxFileName) ; |
|
160 TPtr docIdPtr = path16->Des(); |
|
161 CnvUtfConverter::ConvertToUnicodeFromUtf8( docIdPtr,aLaunchInfo) ; |
|
162 |
|
163 |
|
164 fs.Entry( *path16, fileEntry ); |
|
165 TBool testPath = BaflUtils::FileExists( fs, *path16 ); |
|
166 fs.Close(); |
|
167 if ( !testPath ) |
|
168 { |
|
169 User::Leave( KErrNotFound ); |
|
170 } |
|
171 if ( !( fileEntry.IsDir() ) /*&& testPath */ ) |
|
172 { |
|
173 |
|
174 RApaLsSession session; |
|
175 if(session.Connect() != KErrNone) |
|
176 { |
|
177 return; |
|
178 } |
|
179 |
|
180 // Gets the UID of the application that can handle MIME |
|
181 //type for the given file name. |
|
182 TUid uid; |
|
183 TDataType dataType; |
|
184 //TInt err = session.AppForDocument( pathPtr, uid, dataType ); |
|
185 |
|
186 TInt err = session.AppForDocument( *path16, uid, dataType ); |
|
187 // Runs the default application using the MIME type, dataType. |
|
188 // You can also use the UID to run the application. |
|
189 // If the Type is unrecognized dont do anything |
|
190 if ( !uid.iUid ) |
|
191 { |
|
192 User::LeaveIfError( KErrNotSupported ); |
|
193 } |
|
194 if ( KErrNone == err && uid.iUid ) |
|
195 { |
|
196 TThreadId threadId; |
|
197 TInt err = session.StartDocument( *path16, dataType, |
|
198 threadId ); |
|
199 if ( KErrNone != err ) |
|
200 { |
|
201 User::LeaveIfError( err ); |
|
202 } |
|
203 |
|
204 } |
|
205 |
|
206 session.Close(); |
|
207 } |
|
208 // CleanupStack::PopAndDestroy( path16 ); |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------------- |
|
212 // CFilesSearchPlugin::CFilesSearchPlugin() |
|
213 // constructor |
|
214 // --------------------------------------------------------------------------------- |
|
215 // |
|
216 CFilesSearchPlugin::CFilesSearchPlugin() |
|
217 { |
|
218 |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------------------------------- |
|
222 // CFilesSearchPlugin::ConstructL() |
|
223 // 2nd phase constructor |
|
224 // --------------------------------------------------------------------------------- |
|
225 // |
|
226 void CFilesSearchPlugin::ConstructL() |
|
227 { |
|
228 RResourceFile resourceFile; |
|
229 HBufC* resourceFileName = HBufC::NewL( KMaxFileName ); |
|
230 TPtr resourceFileNamePtr = resourceFileName->Des(); |
|
231 |
|
232 TPtrC driveLetter = TParsePtrC( RProcess().FileName() ).Drive(); |
|
233 RFs fsSession; |
|
234 User::LeaveIfError( fsSession.Connect() ); |
|
235 //Read resource file from ecom resource dir |
|
236 resourceFileNamePtr.Copy( driveLetter ); |
|
237 resourceFileNamePtr.Append( KDC_ECOM_RESOURCE_DIR ); |
|
238 resourceFileNamePtr.Append( KResoureFileName ); |
|
239 |
|
240 CleanupClosePushL( resourceFile ); |
|
241 TFileName fileName = resourceFileName->Des(); |
|
242 BaflUtils::NearestLanguageFile( fsSession,fileName ); |
|
243 resourceFile.OpenL( fsSession, fileName ); |
|
244 resourceFile.ConfirmSignatureL(0); |
|
245 |
|
246 HBufC8* readBuffer = resourceFile.AllocReadLC( R_QGN_SEARCH_TYPES_FILES ); |
|
247 |
|
248 const TPtrC16 ptrReadBuffer( ( TText16* ) readBuffer->Ptr(), |
|
249 ( readBuffer->Length()+1 )>>1 ); |
|
250 |
|
251 iCaption = ptrReadBuffer.AllocL(); |
|
252 |
|
253 CleanupStack::PopAndDestroy( readBuffer ); |
|
254 |
|
255 CleanupStack::Pop( ); |
|
256 resourceFile.Close(); |
|
257 delete resourceFileName; |
|
258 resourceFileName = NULL; |
|
259 fsSession.Close(); |
|
260 } |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |