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