|
1 /* |
|
2 * Copyright (c) 2002-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: Class representing ringing tone |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cphoneringingtone.h" |
|
22 #include <apgcli.h> |
|
23 #include <DRMHelper.h> |
|
24 #include <bldvariant.hrh> |
|
25 #include <pathinfo.h> |
|
26 #include "phoneconstants.h" |
|
27 #include "phonelogger.h" |
|
28 |
|
29 // CONSTANTS |
|
30 // Rich audio file MIME types |
|
31 _LIT(KAac, "audio/aac"); |
|
32 _LIT(KMp3, "audio/mp3"); |
|
33 _LIT(KMpeg, "audio/mpeg"); |
|
34 _LIT(K3gpp, "audio/3gpp"); |
|
35 _LIT(KMp4, "audio/mp4"); |
|
36 _LIT(KAmrWb, "audio/amr-wb"); |
|
37 _LIT(KWavX, "audio/x-wav"); |
|
38 _LIT(KWav, "audio/wav"); |
|
39 |
|
40 // Rich video file MIME types |
|
41 _LIT(KV3gpp, "video/3gpp"); |
|
42 _LIT(KVMp4, "video/mp4"); |
|
43 _LIT(KV3gpp2, "video/3gpp2"); |
|
44 |
|
45 // MACROS |
|
46 |
|
47 // ============================ MEMBER FUNCTIONS =============================== |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CPhoneRingingTone::CPhoneRingingTone |
|
51 // C++ default constructor can NOT contain any code, that |
|
52 // might leave. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CPhoneRingingTone::CPhoneRingingTone( TBool aDrmInPlayback ) : |
|
56 iDrmInPlayback( aDrmInPlayback ) |
|
57 { |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CPhoneRingingTone::ConstructL |
|
62 // Symbian 2nd phase constructor can leave. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void CPhoneRingingTone::ConstructL( const TDesC& aFileName ) |
|
66 { |
|
67 iFileName = aFileName.AllocL(); |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CPhoneRingingTone::NewL |
|
72 // Two-phased constructor. |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CPhoneRingingTone* CPhoneRingingTone::NewL( |
|
76 const TDesC& aFileName, |
|
77 TBool aDrmInPlayback ) |
|
78 { |
|
79 CPhoneRingingTone* self = new( ELeave ) CPhoneRingingTone( |
|
80 aDrmInPlayback ); |
|
81 |
|
82 CleanupStack::PushL( self ); |
|
83 self->ConstructL( aFileName ); |
|
84 CleanupStack::Pop( self ); |
|
85 |
|
86 return self; |
|
87 } |
|
88 |
|
89 // Destructor |
|
90 CPhoneRingingTone::~CPhoneRingingTone() |
|
91 { |
|
92 delete iFileName; |
|
93 delete iMimeType; |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CPhoneRingingTone::SetFileName |
|
98 // (other items were commented in a header). |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 void CPhoneRingingTone::SetFileName( const TDesC& aFileName ) |
|
102 { |
|
103 delete iFileName; |
|
104 iFileName = aFileName.Alloc(); |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CPhoneRingingTone::FileName |
|
109 // (other items were commented in a header). |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 const TDesC& CPhoneRingingTone::FileName() const |
|
113 { |
|
114 // iFileName is never NULL |
|
115 return *iFileName; |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CPhoneRingingTone::MimeType |
|
120 // (other items were commented in a header). |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 const TDesC& CPhoneRingingTone::MimeType() const |
|
124 { |
|
125 if ( iMimeType ) |
|
126 { |
|
127 return *iMimeType; |
|
128 } |
|
129 else |
|
130 { |
|
131 return KNullDesC; |
|
132 } |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CPhoneRingingTone::IsVideoRingingTone |
|
137 // (other items were commented in a header). |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 TBool CPhoneRingingTone::IsVideoRingingTone() |
|
141 { |
|
142 #ifdef RD_VIDEO_AS_RINGING_TONE |
|
143 if ( RefreshMime() != KErrNone ) |
|
144 { |
|
145 // try to handle as audio |
|
146 return EFalse; |
|
147 } |
|
148 |
|
149 TBool isVideo( EFalse ); |
|
150 |
|
151 if ( iMimeType && iMimeType->MatchF( KPhoneRingingToneVideoMime ) != |
|
152 KErrNotFound ) |
|
153 { |
|
154 isVideo = ETrue; |
|
155 } |
|
156 else if ( iMimeType && iMimeType->MatchF( KPhoneRingingToneRealVideoMime ) != |
|
157 KErrNotFound ) |
|
158 { |
|
159 isVideo = ETrue; |
|
160 } |
|
161 |
|
162 if ( isVideo ) |
|
163 { |
|
164 if ( IsFileInRom() && !IsFileInVideoDirectory() ) |
|
165 { |
|
166 // For ROM files check also location, because |
|
167 // MIME check is not fully reliable. |
|
168 isVideo = EFalse; |
|
169 } |
|
170 } |
|
171 |
|
172 return isVideo; |
|
173 #else |
|
174 // if extended security -> refresh MIME |
|
175 if ( iDrmInPlayback ) |
|
176 { |
|
177 RefreshMime(); |
|
178 } |
|
179 |
|
180 return EFalse; |
|
181 #endif |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CPhoneRingingTone::IsFileDrmProtected |
|
186 // (other items were commented in a header). |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 TBool CPhoneRingingTone::IsFileDrmProtected() const |
|
190 { |
|
191 const TDesC& type = MimeType(); |
|
192 |
|
193 if ( type == KAac || type == KMp3 || type == KMpeg || |
|
194 type == K3gpp || type == KMp4 || type == KAmrWb || |
|
195 type == KWavX || type == KWav || type == KV3gpp || |
|
196 type == KVMp4 || type == KV3gpp2 ) |
|
197 { |
|
198 ContentAccess::CContent* content = NULL; |
|
199 TRAPD( err, content = ContentAccess::CContent::NewL( *iFileName ) ); |
|
200 if ( err == KErrNone && content ) |
|
201 { |
|
202 TInt drmProtected( 0 ); |
|
203 content->GetAttribute( ContentAccess::EIsProtected, drmProtected ); |
|
204 delete content; |
|
205 return drmProtected; |
|
206 } |
|
207 } |
|
208 |
|
209 return ETrue; // Other MIMEs can be played without DRM check. |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CPhoneRingingTone::IsFileInRom |
|
214 // (other items were commented in a header). |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 TBool CPhoneRingingTone::IsFileInRom() const |
|
218 { |
|
219 TParsePtrC parsedName( *iFileName ); |
|
220 |
|
221 // Files on rom are not DRM checked |
|
222 if ( parsedName.Drive().CompareF( KPhoneRingingToneDriveZ ) == 0 ) |
|
223 { |
|
224 return ETrue; |
|
225 } |
|
226 else |
|
227 { |
|
228 return EFalse; |
|
229 } |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CPhoneRingingTone::IsFileInVideoDirectory |
|
234 // (other items were commented in a header). |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 TBool CPhoneRingingTone::IsFileInVideoDirectory() const |
|
238 { |
|
239 TParsePtrC parsedName( *iFileName ); |
|
240 |
|
241 if ( PathInfo::PathType( parsedName.DriveAndPath() ) == |
|
242 PathInfo::EVideosPath ) |
|
243 { |
|
244 return ETrue; |
|
245 } |
|
246 else |
|
247 { |
|
248 return EFalse; |
|
249 } |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CPhoneRingingTone::RefreshMime |
|
254 // (other items were commented in a header). |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 TInt CPhoneRingingTone::RefreshMime() |
|
258 { |
|
259 TRAPD( err, RefreshMimeL() ); |
|
260 return err; |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CPhoneRingingTone::RefreshMimeL |
|
265 // (other items were commented in a header). |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 void CPhoneRingingTone::RefreshMimeL() |
|
269 { |
|
270 RApaLsSession apaLsSession; |
|
271 User::LeaveIfError( apaLsSession.Connect() ); |
|
272 CleanupClosePushL( apaLsSession ); |
|
273 |
|
274 TUid dummyUid = { 0 }; |
|
275 TDataType dataType( dummyUid ); |
|
276 |
|
277 User::LeaveIfError( |
|
278 apaLsSession.AppForDocument( *iFileName, dummyUid, dataType ) ); |
|
279 |
|
280 CleanupStack::PopAndDestroy(); // CleanupClosePushL |
|
281 |
|
282 delete iMimeType; |
|
283 iMimeType = NULL; |
|
284 iMimeType = dataType.Des().AllocL(); |
|
285 } |
|
286 |
|
287 // End of File |