|
1 /* |
|
2 * Copyright (c) 2003-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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "content.h" |
|
20 #include "resolver.h" |
|
21 #include "data.h" |
|
22 #include "agentfactory.h" |
|
23 #include "agentinfo.h" |
|
24 #include "agentinterface.h" |
|
25 #include "attributeset.h" |
|
26 #include "agent.h" |
|
27 #include "virtualpath.h" |
|
28 #include "agentfactory.h" |
|
29 |
|
30 #ifndef REMOVE_CAF1 |
|
31 #include "attribute.h" |
|
32 #include "bitset.h" |
|
33 #endif |
|
34 |
|
35 using namespace ContentAccess; |
|
36 |
|
37 EXPORT_C CContent* CContent::NewLC(const TDesC& aURI) |
|
38 { |
|
39 return CContent::NewLC(aURI, EContentShareReadOnly); |
|
40 } |
|
41 |
|
42 EXPORT_C CContent* CContent::NewL(const TDesC& aURI) |
|
43 { |
|
44 return CContent::NewL(aURI, EContentShareReadOnly); |
|
45 } |
|
46 |
|
47 EXPORT_C CContent* CContent::NewLC(const TDesC& aURI, TContentShareMode aShareMode) |
|
48 { |
|
49 CContent* self = new(ELeave) CContent(); |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(aURI, aShareMode); |
|
52 return self; |
|
53 } |
|
54 |
|
55 EXPORT_C CContent* CContent::NewL(const TDesC& aURI, TContentShareMode aShareMode) |
|
56 { |
|
57 CContent* self=CContent::NewLC(aURI, aShareMode); |
|
58 CleanupStack::Pop(self); |
|
59 return self; |
|
60 } |
|
61 |
|
62 EXPORT_C CContent* CContent::NewLC(RFile& aFile) |
|
63 { |
|
64 CContent* self = new(ELeave) CContent(); |
|
65 CleanupStack::PushL(self); |
|
66 self->ConstructL(aFile); |
|
67 return self; |
|
68 } |
|
69 |
|
70 EXPORT_C CContent* CContent::NewL(RFile& aFile) |
|
71 { |
|
72 CContent* self=CContent::NewLC(aFile); |
|
73 CleanupStack::Pop(self); |
|
74 return self; |
|
75 } |
|
76 |
|
77 CContent::CContent() : iDefaultVirtualPath(KNullDesC(), KDefaultContentObject()) |
|
78 { |
|
79 } |
|
80 |
|
81 CContent::~CContent() |
|
82 { |
|
83 delete iAgentContent; |
|
84 |
|
85 if(iVirtualPath) |
|
86 { |
|
87 delete iVirtualPath; |
|
88 } |
|
89 else |
|
90 { |
|
91 iFile.Close(); |
|
92 } |
|
93 |
|
94 // Finished with agent, this closes ECOM handle |
|
95 delete iAgentFactory; |
|
96 REComSession::FinalClose(); |
|
97 } |
|
98 |
|
99 |
|
100 void CContent::ConstructL(RFile &aFile) |
|
101 { |
|
102 // Make our own copy of the file handle |
|
103 User::LeaveIfError(iFile.Duplicate(aFile)); |
|
104 |
|
105 // Rewind the file pointer |
|
106 TInt pos = 0; |
|
107 iFile.Seek(ESeekStart, pos); |
|
108 |
|
109 // For case where CAF is built with an RFile |
|
110 CAgentResolver* resolver = CAgentResolver::NewLC(EFalse); |
|
111 |
|
112 // Find the agent who handles the file |
|
113 CAgentInfo& agentInfo = resolver->ResolveFileL(iFile); |
|
114 |
|
115 // copy the agent name and Uid |
|
116 iAgent = agentInfo.Agent(); |
|
117 |
|
118 // Construct the agent factory (ECOM handle) |
|
119 iAgentFactory = CAgentFactory::NewL(iAgent.ImplementationUid()); |
|
120 |
|
121 // Construct the CAgentContent object |
|
122 iAgentContent = iAgentFactory->CreateContentBrowserL(iFile); |
|
123 |
|
124 // Finished with resolver (and the agentInfo object it owns) |
|
125 CleanupStack::PopAndDestroy(resolver); |
|
126 } |
|
127 |
|
128 void CContent::ConstructL(const TDesC& aURI, TContentShareMode aShareMode) |
|
129 { |
|
130 iShareMode = aShareMode; |
|
131 |
|
132 // Create the agent resolver which will contains a reference to |
|
133 // the agent responsible for this piece of content |
|
134 CAgentResolver* resolver = CAgentResolver::NewLC(EFalse); |
|
135 |
|
136 // Create a temporary buffer used to store the translated version of the URI |
|
137 HBufC* actualUri = HBufC::NewLC(aURI.Length() + KMaxSIDLength); |
|
138 TPtr uri = actualUri->Des(); |
|
139 |
|
140 // Set the TVirtualPathPtr to point to the URI supplied, |
|
141 // this will decode any combined URI into the actual URI and uniqueId |
|
142 // for use in subsequent functions |
|
143 TVirtualPathPtr contentVirtualPath = aURI; |
|
144 |
|
145 // Find the agent who handles the file and translate the URI if it is pointing to a private directory |
|
146 CAgentInfo& agentInfo = resolver->ResolveFileL(contentVirtualPath.URI(), uri, iShareMode); |
|
147 |
|
148 // Set the iVirtualPath to point to the translated URI and the uniqueId |
|
149 iVirtualPath = CVirtualPath::NewL(*actualUri, contentVirtualPath.UniqueId()); |
|
150 |
|
151 iDefaultVirtualPath = *iVirtualPath; |
|
152 |
|
153 // Copy the agent name and Uid |
|
154 iAgent = agentInfo.Agent(); |
|
155 |
|
156 // Construct the agent factory (ECOM handle) |
|
157 iAgentFactory = CAgentFactory::NewL(iAgent.ImplementationUid()); |
|
158 |
|
159 // Construct the agent content browser |
|
160 iAgentContent = iAgentFactory->CreateContentBrowserL(uri, iShareMode); |
|
161 |
|
162 // Finished with resolver and the CAgentInfo object it owns |
|
163 CleanupStack::PopAndDestroy(2, resolver); // actualUri |
|
164 } |
|
165 |
|
166 EXPORT_C TInt CContent::OpenContainer(const TDesC &aUniqueId) |
|
167 { |
|
168 return iAgentContent->OpenContainer(aUniqueId); |
|
169 } |
|
170 |
|
171 EXPORT_C TInt CContent::CloseContainer () |
|
172 { |
|
173 return iAgentContent->CloseContainer(); |
|
174 } |
|
175 |
|
176 EXPORT_C void CContent::GetEmbeddedObjectsL (RStreamablePtrArray<CEmbeddedObject>& aArray) const |
|
177 { |
|
178 iAgentContent->GetEmbeddedObjectsL(aArray); |
|
179 } |
|
180 |
|
181 EXPORT_C void CContent::GetEmbeddedObjectsL (RStreamablePtrArray<CEmbeddedObject>& aArray, TEmbeddedType aType) const |
|
182 { |
|
183 iAgentContent->GetEmbeddedObjectsL(aArray, aType); |
|
184 } |
|
185 |
|
186 EXPORT_C TInt CContent::Search (RStreamablePtrArray<CEmbeddedObject>& aArray, const TDesC8 &aMimeType, TBool aRecursive) |
|
187 { |
|
188 return iAgentContent->Search(aArray, aMimeType, aRecursive); |
|
189 } |
|
190 |
|
191 EXPORT_C TInt CContent::GetAttribute (TInt aAttribute, TInt &aValue) const |
|
192 { |
|
193 return GetAttribute(aAttribute, aValue, iDefaultVirtualPath.UniqueId()); |
|
194 } |
|
195 |
|
196 EXPORT_C TInt CContent::GetAttribute (TInt aAttribute, TInt& aValue, const TDesC &aUniqueId) const |
|
197 { |
|
198 return iAgentContent->GetAttribute(aAttribute, aValue, aUniqueId); |
|
199 } |
|
200 |
|
201 EXPORT_C TInt CContent::GetAttributeSet(RAttributeSet& aAttributeSet) const |
|
202 { |
|
203 return GetAttributeSet(aAttributeSet, iDefaultVirtualPath.UniqueId()); |
|
204 } |
|
205 |
|
206 EXPORT_C TInt CContent::GetAttributeSet(RAttributeSet& aAttributeSet, const TDesC& aUniqueId) const |
|
207 { |
|
208 return iAgentContent->GetAttributeSet(aAttributeSet, aUniqueId); |
|
209 } |
|
210 |
|
211 EXPORT_C TInt CContent::GetStringAttribute (TInt aAttribute, TDes &aValue) const |
|
212 { |
|
213 return GetStringAttribute(aAttribute, aValue, iDefaultVirtualPath.UniqueId()); |
|
214 } |
|
215 |
|
216 EXPORT_C TInt CContent::GetStringAttribute (TInt aAttribute, TDes &aValue, const TDesC &aUniqueId) const |
|
217 { |
|
218 return iAgentContent->GetStringAttribute(aAttribute, aValue, aUniqueId); |
|
219 } |
|
220 |
|
221 EXPORT_C TInt CContent::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet) const |
|
222 { |
|
223 return GetStringAttributeSet(aStringAttributeSet, iDefaultVirtualPath.UniqueId()); |
|
224 } |
|
225 |
|
226 EXPORT_C TInt CContent::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TDesC& aUniqueId) const |
|
227 { |
|
228 return iAgentContent->GetStringAttributeSet(aStringAttributeSet, aUniqueId); |
|
229 } |
|
230 |
|
231 EXPORT_C TInt CContent::AgentSpecificCommand (TInt aCommand, const TDesC8 &aInputBuffer, TDes8 &aOutputBuffer) |
|
232 { |
|
233 return iAgentContent->AgentSpecificCommand(aCommand, aInputBuffer, aOutputBuffer); |
|
234 } |
|
235 |
|
236 EXPORT_C void CContent::AgentSpecificCommand (TInt aCommand, const TDesC8 &aInputBuffer, TDes8 &aOutputBuffer, TRequestStatus &aStatus) |
|
237 { |
|
238 iAgentContent->AgentSpecificCommand(aCommand, aInputBuffer, aOutputBuffer, aStatus); |
|
239 } |
|
240 |
|
241 EXPORT_C void CContent::NotifyStatusChange(TEventMask aMask, TRequestStatus &aStatus) |
|
242 { |
|
243 NotifyStatusChange(aMask, aStatus, iDefaultVirtualPath.UniqueId()); |
|
244 } |
|
245 |
|
246 EXPORT_C void CContent::NotifyStatusChange(TEventMask aMask, TRequestStatus &aStatus, const TDesC &aUniqueId) |
|
247 { |
|
248 iAgentContent->NotifyStatusChange(aMask, aStatus, aUniqueId); |
|
249 } |
|
250 |
|
251 EXPORT_C TInt CContent::CancelNotifyStatusChange(TRequestStatus &aStatus) |
|
252 { |
|
253 return CancelNotifyStatusChange(aStatus, iDefaultVirtualPath.UniqueId()); |
|
254 } |
|
255 |
|
256 EXPORT_C TInt CContent::CancelNotifyStatusChange(TRequestStatus &aStatus, const TDesC &aUniqueId) |
|
257 { |
|
258 return iAgentContent->CancelNotifyStatusChange(aStatus, aUniqueId); |
|
259 } |
|
260 |
|
261 EXPORT_C void CContent::RequestRights(TRequestStatus &aStatus) |
|
262 { |
|
263 RequestRights(aStatus, iDefaultVirtualPath.UniqueId()); |
|
264 } |
|
265 |
|
266 EXPORT_C void CContent::RequestRights(TRequestStatus &aStatus, const TDesC &aUniqueId) |
|
267 { |
|
268 iAgentContent->RequestRights(aStatus, aUniqueId); |
|
269 } |
|
270 |
|
271 EXPORT_C TInt CContent::CancelRequestRights(TRequestStatus &aStatus) |
|
272 { |
|
273 return CancelRequestRights(aStatus, iDefaultVirtualPath.UniqueId()); |
|
274 } |
|
275 |
|
276 EXPORT_C TInt CContent::CancelRequestRights(TRequestStatus &aStatus, const TDesC& aUniqueId) |
|
277 { |
|
278 return iAgentContent->CancelRequestRights(aStatus, aUniqueId); |
|
279 } |
|
280 |
|
281 EXPORT_C void CContent::DisplayInfoL(TDisplayInfo aInfo) const |
|
282 { |
|
283 DisplayInfoL(aInfo, iDefaultVirtualPath.UniqueId()); |
|
284 } |
|
285 |
|
286 EXPORT_C void CContent::DisplayInfoL(TDisplayInfo aInfo, const TDesC& aUniqueId) const |
|
287 { |
|
288 iAgentContent->DisplayInfoL(aInfo, aUniqueId); |
|
289 } |
|
290 |
|
291 EXPORT_C TInt CContent::SetProperty(TAgentProperty aProperty, TInt aValue) |
|
292 { |
|
293 return iAgentContent->SetProperty(aProperty, aValue); |
|
294 } |
|
295 |
|
296 EXPORT_C CData* CContent::OpenContentL(TIntent aIntent) |
|
297 { |
|
298 return OpenContentL(aIntent, iDefaultVirtualPath.UniqueId()); |
|
299 } |
|
300 |
|
301 EXPORT_C CData* CContent::OpenContentLC(TIntent aIntent) |
|
302 { |
|
303 return OpenContentLC(aIntent, iDefaultVirtualPath.UniqueId()); |
|
304 } |
|
305 |
|
306 EXPORT_C CData* CContent::OpenContentL(TIntent aIntent, const TDesC &aUniqueId) |
|
307 { |
|
308 CData* data = OpenContentLC(aIntent, aUniqueId); |
|
309 CleanupStack::Pop(data); |
|
310 return data; |
|
311 } |
|
312 |
|
313 EXPORT_C CData* CContent::OpenContentLC(TIntent aIntent, const TDesC &aUniqueId) |
|
314 { |
|
315 // Open the content object specified by the Unique Id |
|
316 if(iVirtualPath) |
|
317 { |
|
318 // create a CData based upon the URI supplied when this CContent was created |
|
319 return CData::NewLC(iAgent.ImplementationUid(), TVirtualPathPtr(iDefaultVirtualPath.URI(), aUniqueId), aIntent, iShareMode); |
|
320 } |
|
321 else |
|
322 { |
|
323 // create a CData based upon the file handle supplied when this CContent was created |
|
324 return CData::NewLC(iAgent.ImplementationUid(), iFile, aUniqueId, aIntent); |
|
325 } |
|
326 } |
|
327 |
|
328 EXPORT_C const TAgent& CContent::Agent() const |
|
329 { |
|
330 // The agent handling this content |
|
331 return iAgent; |
|
332 } |
|
333 |
|
334 #ifndef REMOVE_CAF1 |
|
335 // Deprecated functions |
|
336 |
|
337 EXPORT_C CData* CContent::OpenContentL(TIntent aIntent, TContentShareMode aShareMode) |
|
338 { |
|
339 CData* data = NULL; |
|
340 // Open the content object specified by the Unique Id |
|
341 if(iVirtualPath) |
|
342 { |
|
343 // create a CData based upon the URI supplied when this CContent was created |
|
344 data = CData::NewLC(iAgent.ImplementationUid(), iDefaultVirtualPath, aIntent, aShareMode); |
|
345 } |
|
346 else |
|
347 { |
|
348 // create a CData based upon the file handle supplied when this CContent was created |
|
349 data = CData::NewLC(iAgent.ImplementationUid(), iFile, iDefaultVirtualPath.UniqueId(), aIntent); |
|
350 } |
|
351 CleanupStack::Pop(data); |
|
352 return data; |
|
353 } |
|
354 |
|
355 EXPORT_C CAttribute* CContent::NewAttributeL(TBool aPreloaded) |
|
356 { |
|
357 return NewAttributeL(aPreloaded, EContentShareReadOnly); |
|
358 } |
|
359 |
|
360 EXPORT_C CAttribute* CContent::NewAttributeL(TBool aPreloaded, TContentShareMode aShareMode) |
|
361 { |
|
362 CAttribute* attr = NULL; |
|
363 |
|
364 if(iVirtualPath) |
|
365 { |
|
366 // if we were opened with a file name |
|
367 attr = CAttribute::NewLC(iAgent.ImplementationUid(), iDefaultVirtualPath.URI(), aShareMode); |
|
368 } |
|
369 else |
|
370 { |
|
371 // if we were opened with a file handle |
|
372 attr = CAttribute::NewLC(iAgent.ImplementationUid(), iFile); |
|
373 } |
|
374 |
|
375 // If aPreloaded is set, query the agent immediately for all the attributes |
|
376 if (aPreloaded) |
|
377 { |
|
378 attr->QuerySet().SetAll(); |
|
379 attr->GetL(); |
|
380 } |
|
381 |
|
382 CleanupStack::Pop(attr); |
|
383 return attr; |
|
384 } |
|
385 |
|
386 #endif // REMOVE_CAF1 |
|
387 |
|
388 |
|
389 // DLL entry point - only for EKA1 |