|
1 /* |
|
2 * Copyright (c) 2005 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: |
|
15 * Base class for different media type info classes. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include <e32std.h> |
|
24 #include <e32base.h> // CBase |
|
25 #include <apmstd.h> // TDataType |
|
26 #include <f32file.h> // RFs, RFile |
|
27 #include <apgcli.h> // RApaLsSession |
|
28 |
|
29 #include <caf/caf.h> |
|
30 #include <DRMCommon.h> // Just for error codes |
|
31 #include <DRMHelper.h> |
|
32 #include <fileprotectionresolver.h> |
|
33 |
|
34 #include "MsgMediaInfo.h" |
|
35 |
|
36 // EXTERNAL DATA STRUCTURES |
|
37 |
|
38 // EXTERNAL FUNCTION PROTOTYPES |
|
39 |
|
40 // CONSTANTS |
|
41 |
|
42 // MACROS |
|
43 |
|
44 // LOCAL CONSTANTS AND MACROS |
|
45 |
|
46 // MODULE DATA STRUCTURES |
|
47 |
|
48 // LOCAL FUNCTION PROTOTYPES |
|
49 |
|
50 // FORWARD DECLARATIONS |
|
51 |
|
52 // ============================ MEMBER FUNCTIONS =============================== |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CMsgMediaInfo::NewL |
|
56 // Two-phased constructor. |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 EXPORT_C CMsgMediaInfo* CMsgMediaInfo::NewL( RFile& aFile, |
|
60 TDataType& aMimeType, |
|
61 TMsgMediaType aMediaType ) |
|
62 { |
|
63 CMsgMediaInfo* self = new( ELeave ) CMsgMediaInfo( aMimeType, aMediaType ); |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL( aFile ); |
|
66 CleanupStack::Pop( self ); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CMsgMediaInfo::CMsgMediaInfo |
|
72 // C++ default constructor can NOT contain any code, that |
|
73 // might leave. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 CMsgMediaInfo::CMsgMediaInfo( TDataType& aDataType, TMsgMediaType aMediaType ): |
|
77 CActive( EPriorityLow ), |
|
78 iMimeType( aDataType ), |
|
79 iFileSize( 0 ), |
|
80 iModificationTime(), |
|
81 iMediaType( aMediaType ), |
|
82 iDuration( 0 ), |
|
83 iProtection( EFileProtNoProtection ), |
|
84 iParsed( EFalse ), |
|
85 iHandlerAppUid( KNullUid ) |
|
86 { |
|
87 CActiveScheduler::Add( this ); |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CMsgMediaInfo::ConstructL |
|
92 // Symbian 2nd phase constructor can leave. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CMsgMediaInfo::ConstructL( RFile& aFile ) |
|
96 { |
|
97 TFileName fullName; |
|
98 User::LeaveIfError( aFile.FullName( fullName ) ); |
|
99 User::LeaveIfError( aFile.Size( iFileSize ) ); |
|
100 User::LeaveIfError( aFile.Modified( iModificationTime ) ); |
|
101 iFullFilePath = fullName.AllocL(); |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // Destructor |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 CMsgMediaInfo::~CMsgMediaInfo() |
|
109 { |
|
110 Cancel(); |
|
111 iObserver = NULL; |
|
112 iDRMHelper = NULL; |
|
113 iFile.Close(); |
|
114 delete iFullFilePath; |
|
115 delete iContentURI; |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CMsgMediaInfo::ParseInfoDetails |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 EXPORT_C void CMsgMediaInfo::ParseInfoDetails( RFile& aFile, CDRMHelper& aDRMHelper, MMediaInfoObserver& aObserver ) |
|
123 { |
|
124 iObserver = &aObserver; |
|
125 iDRMHelper = &aDRMHelper; |
|
126 iFile.Duplicate( aFile ); |
|
127 // Actual parsing is done in RunL (of each media info class). |
|
128 //CompleteSelf( KErrNone ); |
|
129 RunL(); |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CMsgMediaInfo::ParseInfoDetailsL |
|
134 // |
|
135 // Deprecated. Use the non-leaving version instead. |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 EXPORT_C void CMsgMediaInfo::ParseInfoDetailsL( RFile& aFile, CDRMHelper& aDRMHelper, MMediaInfoObserver& aObserver ) |
|
139 { |
|
140 ParseInfoDetails( aFile, aDRMHelper, aObserver ); |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CMsgMediaInfo::SetFileL |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 EXPORT_C void CMsgMediaInfo::SetFileL( RFile& aFile ) |
|
148 { |
|
149 TBool oldParsed = iParsed; |
|
150 iParsed = EFalse; |
|
151 |
|
152 delete iFullFilePath; |
|
153 iFullFilePath = NULL; |
|
154 |
|
155 TFileName fullName; |
|
156 User::LeaveIfError( aFile.FullName( fullName ) ); |
|
157 User::LeaveIfError( aFile.Size( iFileSize ) ); |
|
158 User::LeaveIfError( aFile.Modified( iModificationTime ) ); |
|
159 iFullFilePath = fullName.AllocL(); |
|
160 |
|
161 iParsed = oldParsed; |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CMsgMediaInfo::Corrupt |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 EXPORT_C TBool CMsgMediaInfo::Corrupt() const |
|
169 { |
|
170 TBool corrupt( ETrue ); |
|
171 switch ( iParseError ) |
|
172 { |
|
173 case KErrNone: |
|
174 case KErrNoMemory: |
|
175 case KErrInUse: |
|
176 case DRMCommon::ENoRights: |
|
177 case DRMCommon::ERightsExpired: |
|
178 case DRMCommon::EInvalidRights: |
|
179 corrupt = EFalse; |
|
180 break; |
|
181 default: |
|
182 // All other errors are interpreted as corrupt |
|
183 break; |
|
184 } |
|
185 return corrupt; |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CMsgMediaInfo::DoCancel |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 void CMsgMediaInfo::DoCancel() |
|
193 { |
|
194 iFile.Close(); |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CMsgMediaInfo::RunL |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 void CMsgMediaInfo::RunL() |
|
202 { |
|
203 // Never fails since does actually nothing. |
|
204 iParsed = ETrue; |
|
205 CompleteObserver(); |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CMsgMediaInfo::RunError |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 TInt CMsgMediaInfo::RunError( TInt aError ) |
|
213 { |
|
214 CompleteSelf( aError ); |
|
215 return KErrNone; |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CMsgMediaInfo::CompleteSelf |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 void CMsgMediaInfo::CompleteSelf( TInt aError ) |
|
223 { |
|
224 iStatus = KRequestPending; |
|
225 TRequestStatus* pStatus = &iStatus; |
|
226 SetActive(); |
|
227 User::RequestComplete( pStatus, aError ); |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CMsgMediaInfo::CompleteSelf |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 void CMsgMediaInfo::CompleteObserver() |
|
235 { |
|
236 iFile.Close(); |
|
237 ReleaseRights(); |
|
238 iDRMHelper = NULL; |
|
239 iObserver->MediaInfoParsed(); |
|
240 iObserver = NULL; |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CMsgMediaInfo::FreezeRights |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 void CMsgMediaInfo::FreezeRights() |
|
248 { |
|
249 if ( iProtection & ( EFileProtForwardLocked | EFileProtSuperDistributable ) && |
|
250 iContentURI && iContentURI->Length() ) |
|
251 { |
|
252 TInt err = iDRMHelper->Consume2( |
|
253 *iContentURI, |
|
254 ContentAccess::EInstall, |
|
255 CDRMHelper::EStart ); |
|
256 if ( !err ) |
|
257 { |
|
258 iConsumed = ETrue; |
|
259 } |
|
260 } |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CMsgMediaInfo::ReleaseRights |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 void CMsgMediaInfo::ReleaseRights() |
|
268 { |
|
269 if ( iConsumed ) |
|
270 { |
|
271 /*TInt ignore =*/ |
|
272 iDRMHelper->Consume2( |
|
273 *iContentURI, |
|
274 ContentAccess::EInstall, |
|
275 CDRMHelper::EFinish ); |
|
276 iConsumed = EFalse; |
|
277 } |
|
278 } |
|
279 |
|
280 // End of File |