|
1 /* |
|
2 * Copyright (c) 2010 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: MDS to CPIX Document fetcher |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cpixdocfetcher.h" |
|
20 #include "csearchdocument.h" |
|
21 #include <mdeobject.h> |
|
22 #include <mdccommon.h> |
|
23 #include <mdeitem.h> |
|
24 #include <mdeconstants.h> |
|
25 #include <mdeobjectdef.h> |
|
26 #include "harvesterserverlogger.h" |
|
27 |
|
28 #define CPIX_MIMETYPE_FIELD L"_mimetype" |
|
29 #define LCPIX_MIMETYPE_FIELD L"_mimetype" |
|
30 const TInt KStartPosition = 2; //Start position of absolute path |
|
31 const TInt KDrivePosition = 0; //Drive position in object Uri |
|
32 const TInt KMaxMediaLength = 14; |
|
33 const TInt KMaxExtLength = 5; |
|
34 //To unsigned decimal representation as UIds are out of range for signed decimal |
|
35 _LIT(KFormat, "%u"); |
|
36 _LIT(KNameField, "Name"); |
|
37 _LIT(KMediaIdField, "MediaId"); |
|
38 _LIT(KExtensionField, "Extension"); |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CCPIXDocFetcher::NewL() |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CCPIXDocFetcher* CCPIXDocFetcher::NewL() |
|
45 { |
|
46 CCPIXDocFetcher* self = CCPIXDocFetcher::NewLC(); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CCPIXDocFetcher::NewLC() |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CCPIXDocFetcher* CCPIXDocFetcher::NewLC() |
|
56 { |
|
57 CCPIXDocFetcher* self = new (ELeave) CCPIXDocFetcher(); |
|
58 CleanupStack::PushL(self); |
|
59 self->ConstructL(); |
|
60 return self; |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CCPIXDocFetcher::~CCPIXDocFetcher() |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 CCPIXDocFetcher::~CCPIXDocFetcher() |
|
68 { |
|
69 iFs.Close(); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CCPIXDocFetcher::~ConstructL() |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CCPIXDocFetcher::ConstructL() |
|
77 { |
|
78 //Heap variables if any |
|
79 User::LeaveIfError(iFs.Connect()); |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CCPIXDocFetcher::CCPIXDocFetcher() |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 CCPIXDocFetcher::CCPIXDocFetcher() |
|
87 { |
|
88 |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CCPIXDocFetcher::GetCpixDocumentL() |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 CSearchDocument* CCPIXDocFetcher::GetCpixDocumentL(const CMdEObject& aObject, |
|
96 const TDesC& aAppClass, |
|
97 CMdEObjectDef& aObjectDef) |
|
98 { |
|
99 CPIXLOGSTRING("START CCPIXDocFetcher::GetCpixDocumentL"); |
|
100 CSearchDocument* index_item = NULL; |
|
101 if(aObject.Uri() != KNullDesC) //Uri is must have property we will store items which has URI |
|
102 { |
|
103 SetAbsoluteURI(aObject.Uri());//Convert URI to absolute path |
|
104 index_item = CSearchDocument::NewLC(GetUri(), aAppClass); |
|
105 //Uri is our Document ID |
|
106 AddFiledtoDocumentL(*index_item, |
|
107 KNameField, //URI as Name field |
|
108 GetUri()); |
|
109 //Store media ID for client to generate path and launch corresponding Item |
|
110 TBuf<KMaxMediaLength> mediaBuf; |
|
111 |
|
112 //As the MDS database is storing incorrect MediaIds, fetch the uniqueid from the |
|
113 //file system.If the issue is fixed in 10.1 then Ids from MDS can be directly used |
|
114 |
|
115 //GetMediaIdDescriptor(aObject.MediaId(),mediaBuf); |
|
116 GetMediaIdDescriptorFromFsL(aObject.Uri(),mediaBuf); |
|
117 //Uri is our Document ID |
|
118 AddFiledtoDocumentL(*index_item, KMediaIdField, mediaBuf, |
|
119 CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized); |
|
120 CPIXLOGSTRING("CCPIXDocFetcher::GetCpixDocumentL Standard Property URI, Media ID Added"); |
|
121 |
|
122 //Get the media file extension and store |
|
123 TBuf<KMaxExtLength> extension; |
|
124 GetExtension(aObject.Uri(),extension); |
|
125 AddFiledtoDocumentL( *index_item, KExtensionField, extension ); |
|
126 |
|
127 CMdEProperty* property(NULL); |
|
128 CMdEPropertyDef& titlePropDef = aObjectDef.GetPropertyDefL(MdeConstants::Object::KTitleProperty ); |
|
129 if(aObject.Property( titlePropDef, property ) != KErrNotFound) |
|
130 { |
|
131 //Add field to document |
|
132 CMdETextProperty* textProperty = ( CMdETextProperty* ) property; |
|
133 if(textProperty->Value() != KNullDesC) |
|
134 { |
|
135 AddFiledtoDocumentL(*index_item, |
|
136 MdeConstants::Object::KTitleProperty, |
|
137 textProperty->Value()); |
|
138 index_item->AddExcerptL(textProperty->Value()); |
|
139 } |
|
140 else |
|
141 { |
|
142 index_item->AddExcerptL(aObject.Uri()); |
|
143 } |
|
144 } |
|
145 else |
|
146 { |
|
147 //No property title |
|
148 index_item->AddExcerptL(aObject.Uri()); |
|
149 } |
|
150 //Item type as MIME type |
|
151 CMdEPropertyDef& mimeTypePropDef = aObjectDef.GetPropertyDefL(MdeConstants::Object::KItemTypeProperty); |
|
152 if(aObject.Property( mimeTypePropDef, property )!= KErrNotFound) |
|
153 { |
|
154 //Add field to document |
|
155 CMdETextProperty* textProperty = ( CMdETextProperty* ) property; |
|
156 AddFiledtoDocumentL(*index_item, |
|
157 _L(CPIX_MIMETYPE_FIELD), |
|
158 textProperty->Value(), |
|
159 CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized); |
|
160 } |
|
161 CleanupStack::Pop(index_item);//pop up |
|
162 } |
|
163 CPIXLOGSTRING("END CCPIXDocFetcher::GetCpixDocumentL"); |
|
164 return index_item; |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CCPIXDocFetcher::GetUri() |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 const TDesC& CCPIXDocFetcher::GetUri() |
|
172 { |
|
173 return iUri; |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CCPIXDocFetcher::GetMediaIdDescriptor() |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 void CCPIXDocFetcher::GetMediaIdDescriptor(const TUint32& aMediaId, |
|
181 TDes& aMediaIDBuf) |
|
182 { |
|
183 aMediaIDBuf.Format(_L("%d"),aMediaId); |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CCPIXDocFetcher::GetMediaIdDescriptorFromFs() |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 void CCPIXDocFetcher::GetMediaIdDescriptorFromFsL(const TDesC& aUri, |
|
191 TDes& aMediaIDBuf) |
|
192 { |
|
193 TVolumeInfo volumeInfo; |
|
194 TInt driveNumber; |
|
195 TChar driveLetter; |
|
196 driveLetter = aUri[KDrivePosition]; |
|
197 User::LeaveIfError(iFs.CharToDrive(driveLetter,driveNumber)); |
|
198 User::LeaveIfError(iFs.Volume(volumeInfo,driveNumber)); |
|
199 aMediaIDBuf.Format(KFormat, volumeInfo.iUniqueID); |
|
200 } |
|
201 |
|
202 void CCPIXDocFetcher::GetExtension(const TDesC& aUri, |
|
203 TDes& aExtension) |
|
204 { |
|
205 TInt pos = aUri.LocateReverse('.'); |
|
206 if(pos > 0) |
|
207 { |
|
208 aExtension.Copy(aUri.Mid(pos+1)); |
|
209 } |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CCPIXDocFetcher::SetAbsoluteURI() |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 void CCPIXDocFetcher::SetAbsoluteURI(const TDesC& aUri) |
|
217 { |
|
218 iUri.Copy(aUri.Mid(KStartPosition)); |
|
219 } |
|
220 |
|
221 // ----------------------------------------------------------------------------- |
|
222 // CCPIXDocFetcher::AddFiledtoDocumentL() |
|
223 // ----------------------------------------------------------------------------- |
|
224 // |
|
225 void CCPIXDocFetcher::AddFiledtoDocumentL(CSearchDocument& aSearchDoc, |
|
226 const TDesC& aFiledName, |
|
227 const TDesC& aValue, |
|
228 TInt aConfig) |
|
229 { |
|
230 if(aValue != KNullDesC) |
|
231 aSearchDoc.AddFieldL(aFiledName, aValue, aConfig); |
|
232 else |
|
233 aSearchDoc.AddFieldL(aFiledName, KNullDesC, aConfig); |
|
234 } |
|
235 //End of life |