1 /* |
|
2 * Copyright (c) 2006-2007 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: Wrapper for media gallery and profiles libraries. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <MProfile.h> |
|
19 #include <MProfileTones.h> |
|
20 #include <MProfilesNamesArray.h> |
|
21 #include <MProfileEngineExtended.h> |
|
22 #include <MProfileSetExtraTones.h> |
|
23 #include <MProfileSetTones.h> |
|
24 #include <MProfileExtended.h> |
|
25 #include <MProfileName.h> |
|
26 |
|
27 #include <DRMHelper.h> |
|
28 |
|
29 #ifdef RD_CONTENTNOTIFICATION |
|
30 #include <contentnotification.hrh> |
|
31 #include <contentcreatedevent.h> |
|
32 #include <contentnotification.h> |
|
33 #endif //RD_CONTENTNOTIFICATION |
|
34 #include <coemain.h> |
|
35 |
|
36 #include "pslnprofilesettingsloader.h" |
|
37 #include "PslnConst.h" |
|
38 |
|
39 #ifdef RD_CONTENTNOTIFICATION |
|
40 const TInt KPslnEventArraySize = 2; |
|
41 #endif // RD_CONTENTNOTIFICATION |
|
42 |
|
43 // ======== MEMBER FUNCTIONS ======== |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // C++ default constructor can NOT contain any code, that might leave. |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CPslnProfileSettingsLoader::CPslnProfileSettingsLoader() |
|
50 { |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Two-phased constructor. |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CPslnProfileSettingsLoader* CPslnProfileSettingsLoader::NewL() |
|
58 { |
|
59 CPslnProfileSettingsLoader* self = |
|
60 new( ELeave ) CPslnProfileSettingsLoader(); |
|
61 |
|
62 return self; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // Destructor |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CPslnProfileSettingsLoader::~CPslnProfileSettingsLoader() |
|
70 { |
|
71 #ifdef RD_CONTENTNOTIFICATION |
|
72 if ( iEventArray ) |
|
73 { |
|
74 iEventArray->Delete( 0 ); |
|
75 iEventArray->Reset(); |
|
76 } |
|
77 delete iEventArray; |
|
78 #endif // RD_CONTENTNOTIFICATION |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // Sets tone for all profiles. |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 void CPslnProfileSettingsLoader::SetToneForProfilesL( |
|
86 TInt aType, TDes& aFullName ) |
|
87 { |
|
88 MProfileEngineExtended* profileEngine = CreateProfileEngineExtendedL(); |
|
89 CleanupReleasePushL( *profileEngine ); |
|
90 MProfilesNamesArray* profileArray = profileEngine->ProfilesNamesArrayLC(); |
|
91 |
|
92 TInt arrayCount( profileArray->MdcaCount() ); |
|
93 TInt arrayIndex( 0 ); |
|
94 TInt profileId( 0 ); |
|
95 TInt activeId( profileEngine->ActiveProfileId() ); |
|
96 |
|
97 while( arrayIndex < arrayCount ) |
|
98 { |
|
99 profileId = profileArray->ProfileName( arrayIndex )->Id(); |
|
100 // Updating of the active profile will be done last to make sure that |
|
101 // UI gets the new value of the ringing tone if settings view is active |
|
102 // and it is containing settings of another than active profile |
|
103 if( profileId != activeId ) |
|
104 { |
|
105 TRAPD(r, DoSetProfileToneL( profileEngine, profileId, aType, aFullName )); |
|
106 // Filter situation when profile is not allowed to be changed |
|
107 // e.g. Drive-profile |
|
108 if( ( r != KErrNone ) && ( r != KErrAccessDenied ) ) |
|
109 { |
|
110 User::Leave( r ); |
|
111 } |
|
112 } |
|
113 arrayIndex ++; |
|
114 } |
|
115 |
|
116 // Update the active profile: |
|
117 TRAPD(r, DoSetProfileToneL( profileEngine, activeId, aType, aFullName )); |
|
118 if( ( r != KErrNone ) && ( r != KErrAccessDenied ) ) |
|
119 { |
|
120 User::Leave( r ); |
|
121 } |
|
122 CleanupStack::PopAndDestroy( 2 ); //profileEngine,profileArray |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // Do Sets tone for all profiles. |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void CPslnProfileSettingsLoader::DoSetProfileToneL( MProfileEngineExtended* aProfileEngine, |
|
130 TInt aProfileId, TInt aType,const TDesC& aFileName ) |
|
131 { |
|
132 MProfileExtended* profile = aProfileEngine->ProfileLC( aProfileId ); |
|
133 CDRMHelper* drmHelper = CDRMHelper::NewLC(); |
|
134 |
|
135 // Get the old tone in order to remove it from the automated content list |
|
136 TFileName oldTone( ToneL( *profile, aType ) ); |
|
137 |
|
138 // Replace the old tone with the new tone |
|
139 SetToneL( *profile, aType, aFileName ); |
|
140 |
|
141 // Commit changes. Write the new settings to the Profiles Engine |
|
142 aProfileEngine->CommitChangeL( *profile ); |
|
143 |
|
144 // Register file as automated content |
|
145 TInt err( SetAutomated( drmHelper, aType, aFileName ) ); |
|
146 if( err == KErrNone ) |
|
147 { |
|
148 // Remove old tone from the automated content list |
|
149 RemoveAutomated( drmHelper,oldTone ); |
|
150 } |
|
151 else |
|
152 { |
|
153 // Put the old tone back into Profiles: |
|
154 TRAP_IGNORE( |
|
155 SetToneL( *profile, aType, oldTone ); |
|
156 aProfileEngine->CommitChangeL( *profile ); |
|
157 ); |
|
158 } |
|
159 |
|
160 CleanupStack::PopAndDestroy( 2 ); // profile,drmHelper |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // SetTones. |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 void CPslnProfileSettingsLoader::SetToneL( MProfileExtended& aProfile, |
|
168 TInt aType, const TDesC& aFileName ) |
|
169 { |
|
170 MProfileSetTones& setTones = aProfile.ProfileSetTones(); |
|
171 switch ( aType ) |
|
172 { |
|
173 case EAknsMinorSoundRingingTone: |
|
174 setTones.SetRingingTone1L( aFileName ); |
|
175 break; |
|
176 case EAknsMinorSoundMessageAlert: |
|
177 setTones.SetMessageAlertToneL( aFileName ); |
|
178 break; |
|
179 default: |
|
180 User::Leave( KErrArgument ); |
|
181 break; |
|
182 } |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // Read Tones. |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 const TDesC& CPslnProfileSettingsLoader::ToneL( MProfileExtended& aProfile, |
|
190 TInt aType ) |
|
191 { |
|
192 const MProfileTones& tones = aProfile.ProfileTones(); |
|
193 switch ( aType ) |
|
194 { |
|
195 case EAknsMinorSoundRingingTone: |
|
196 { |
|
197 return tones.RingingTone1(); |
|
198 } |
|
199 case EAknsMinorSoundMessageAlert: |
|
200 { |
|
201 return tones.MessageAlertTone(); |
|
202 } |
|
203 default: |
|
204 User::Leave( KErrArgument ); |
|
205 break; |
|
206 } |
|
207 return KNullDesC; |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // SetAutomated |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 TInt CPslnProfileSettingsLoader::SetAutomated( CDRMHelper* aDrmHelper,TInt aType, |
|
215 const TDesC& aFileName ) |
|
216 { |
|
217 switch ( aType ) |
|
218 { |
|
219 case EAknsMinorSoundRingingTone: |
|
220 aDrmHelper->SetAutomatedType( CDRMHelper::EAutomatedTypeRingingTone ); |
|
221 break; |
|
222 case EAknsMinorSoundMessageAlert: |
|
223 aDrmHelper->SetAutomatedType( CDRMHelper::EAutomatedTypeMessageAlert ); |
|
224 break; |
|
225 default: |
|
226 aDrmHelper->SetAutomatedType( CDRMHelper::EAutomatedTypeOther ); |
|
227 } |
|
228 return aDrmHelper->SetAutomatedSilent( aFileName, EFalse ); |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // RemoveAutomated |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void CPslnProfileSettingsLoader::RemoveAutomated( CDRMHelper* aDrmHelper,const TDesC& aFileName ) |
|
236 { |
|
237 aDrmHelper->RemoveAutomatedPassive( aFileName ); // ignore return value |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // Indicates to the Media Gallery that new file has been copied. |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 void CPslnProfileSettingsLoader::IndicateFileUpdationL( const TDesC& aFullPath ) |
|
245 { |
|
246 // Notice: this code is used to avoid the building warning! |
|
247 aFullPath.Length(); |
|
248 #ifdef RD_CONTENTNOTIFICATION |
|
249 CContentNotification* notifier = CContentNotification::NewL(); |
|
250 CleanupStack::PushL( notifier ); |
|
251 |
|
252 if ( iEventArray ) |
|
253 { |
|
254 iEventArray->Delete( 0 ); |
|
255 iEventArray->Reset(); |
|
256 delete iEventArray; |
|
257 iEventArray = NULL; |
|
258 } |
|
259 |
|
260 iEventArray = |
|
261 new CArrayFixFlat<CContentNotificationEvent*>(KPslnEventArraySize); |
|
262 |
|
263 // Nofication about new content |
|
264 CContentNotificationEvent* event = |
|
265 CContentCreatedEvent::NewL( aFullPath ); |
|
266 CleanupStack::PushL( event ); |
|
267 iEventArray->AppendL( event ); |
|
268 CleanupStack::Pop( event ); // array owns the event |
|
269 |
|
270 // Send all notification event with one call |
|
271 User::LeaveIfError( notifier->SendNotification( iEventArray->Array() ) ); |
|
272 delete event; |
|
273 event = NULL; |
|
274 CleanupStack::PopAndDestroy( notifier ); |
|
275 #endif //RD_CONTENTNOTIFICATION |
|
276 } |
|
277 |
|
278 //---------------------------------------------------------------------------- |
|
279 // Launcher gate function |
|
280 //---------------------------------------------------------------------------- |
|
281 EXPORT_C TAny* GateFunction() |
|
282 { |
|
283 CPslnProfileSettingsLoader* launcher = NULL; |
|
284 TRAPD( err, launcher = CPslnProfileSettingsLoader::NewL() ); |
|
285 if( err != KErrNone ) |
|
286 { |
|
287 return NULL; |
|
288 } |
|
289 return launcher; |
|
290 } |
|
291 |
|
292 // End of File |
|