|
1 /* |
|
2 * Copyright (c) 2006 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: Handles the volume, gets the initial volume from central |
|
15 * repository and monitors changes in volume. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <centralrepository.h> |
|
21 #include <ProfileEngineSDKCRKeys.h> |
|
22 #include <browseruisdkcrkeys.h> |
|
23 |
|
24 #include "BavpLogger.h" |
|
25 #include "BavpVolumeHandler.h" |
|
26 #include "BavpVolumeObserver.h" |
|
27 |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CBavpVolumeHandler::NewL |
|
31 // Two-phased constructor. |
|
32 // ---------------------------------------------------------------------------- |
|
33 CBavpVolumeHandler* CBavpVolumeHandler::NewL( MBavpVolumeObserver* aObserver ) |
|
34 { |
|
35 Log( EFalse, _L("CBavpVolumeHandler::NewL") ); |
|
36 |
|
37 CBavpVolumeHandler* self = new (ELeave) CBavpVolumeHandler( aObserver ); |
|
38 CleanupStack::PushL( self ); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop( self ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // CBavpVolumeHandler::CBavpVolumeHandler |
|
46 // C++ default constructor can NOT contain any code, that |
|
47 // might leave. |
|
48 // ---------------------------------------------------------------------------- |
|
49 CBavpVolumeHandler::CBavpVolumeHandler( MBavpVolumeObserver* aObserver ) |
|
50 : iObserver( aObserver ) |
|
51 { |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CBavpVolumeHandler::ConstructL |
|
56 // Symbian 2nd phase constructor can leave. |
|
57 // ----------------------------------------------------------------------------- |
|
58 void CBavpVolumeHandler::ConstructL() |
|
59 { |
|
60 Log( EFalse, _L("CBavpVolumeHandler::ConstructL") ); |
|
61 |
|
62 iCurrentVolume = KCRVolume5; |
|
63 iCurrentProfile = KGeneralProfile; |
|
64 |
|
65 // Get volume settings from central repository |
|
66 iVolumeRepository = CRepository::NewL( KCRUidBrowser ); |
|
67 iVolumeRepository->Get( KBrowserMediaVolumeControl, iCurrentVolume ); |
|
68 |
|
69 // If media volume key exists, watch it for changes |
|
70 iVolumeCRHandler = CCenRepNotifyHandler::NewL( *this, *iVolumeRepository, |
|
71 CCenRepNotifyHandler::EIntKey, |
|
72 (TUint32)KBrowserMediaVolumeControl); |
|
73 iVolumeCRHandler->StartListeningL(); |
|
74 iPreviousVolume = iCurrentVolume; |
|
75 |
|
76 // Get the current profile |
|
77 iProfileRepository = CRepository::NewL( KCRUidProfileEngine ); |
|
78 iProfileRepository->Get( KProEngActiveProfile, iCurrentProfile ); |
|
79 |
|
80 // Watch the Profile changes using a CR Notify Handler |
|
81 iProfileCRHandler = CCenRepNotifyHandler::NewL( *this, *iProfileRepository, |
|
82 CCenRepNotifyHandler::EIntKey, |
|
83 (TUint32)KProEngActiveProfile ); |
|
84 iProfileCRHandler->StartListeningL(); |
|
85 |
|
86 // Now that we have initial volume and profile, lets use them. |
|
87 // Check if we're in Silent profile or Meeting profile. |
|
88 if ( iCurrentProfile == KSilentProfile || |
|
89 iCurrentProfile == KMeetingProfile ) |
|
90 { |
|
91 // Mute the volume, we already saved the CR volume |
|
92 // as iPreviousVolume |
|
93 iCurrentVolume = KCRVolumeMute; |
|
94 } |
|
95 |
|
96 // Tell observer (BavpController) the initial volume |
|
97 if ( iObserver ) |
|
98 { |
|
99 iObserver->UpdateVolume( iCurrentVolume ); |
|
100 } |
|
101 } |
|
102 |
|
103 // ---------------------------------------------------------------------------- |
|
104 // CBavpVolumeHandler::~CBavpVolumeHandler |
|
105 // Destructor |
|
106 // ---------------------------------------------------------------------------- |
|
107 CBavpVolumeHandler::~CBavpVolumeHandler() |
|
108 { |
|
109 Log( EFalse, _L("CBavpVolumeHandler::~CBavpVolumeHandler") ); |
|
110 |
|
111 // Clean up the media volume CR and CR Handler |
|
112 if ( iVolumeCRHandler ) |
|
113 { |
|
114 iVolumeCRHandler->StopListening(); |
|
115 delete iVolumeCRHandler; |
|
116 } |
|
117 |
|
118 delete iVolumeRepository; |
|
119 |
|
120 // Clean up the Profile CR and CR Handler |
|
121 if ( iProfileCRHandler ) |
|
122 { |
|
123 iProfileCRHandler->StopListening(); |
|
124 delete iProfileCRHandler; |
|
125 } |
|
126 |
|
127 delete iProfileRepository; |
|
128 |
|
129 } |
|
130 |
|
131 // ---------------------------------------------------------------------------- |
|
132 // CBavpVolumeHandler::HandleNotifyInt() |
|
133 // Handles volume and profile changes in CR |
|
134 // ---------------------------------------------------------------------------- |
|
135 void CBavpVolumeHandler::HandleNotifyInt( const TUint32 aKeyId, TInt aNewValue ) |
|
136 { |
|
137 if ( aKeyId == KBrowserMediaVolumeControl && aNewValue != iCurrentVolume ) |
|
138 { |
|
139 // Media Volume property updated, and it changed |
|
140 if ( iCurrentProfile == KSilentProfile || |
|
141 iCurrentProfile == KMeetingProfile ) |
|
142 { |
|
143 // We got a new volume, and Profile is "quiet", save and use later |
|
144 iPreviousVolume = aNewValue; |
|
145 } |
|
146 else |
|
147 { |
|
148 // We got a new volume and Profile allows us to use it |
|
149 iCurrentVolume = aNewValue; |
|
150 } |
|
151 } |
|
152 else if ( aKeyId == KProEngActiveProfile && aNewValue != iCurrentProfile ) |
|
153 { |
|
154 // Profile property updated, and it changed |
|
155 iCurrentProfile = aNewValue; |
|
156 |
|
157 // If we got a change in profile, mute or unmute |
|
158 if ( iCurrentProfile == KSilentProfile || |
|
159 iCurrentProfile == KMeetingProfile ) |
|
160 { |
|
161 // Mute the volume |
|
162 iPreviousVolume = iCurrentVolume; |
|
163 iCurrentVolume = KCRVolumeMute; |
|
164 } |
|
165 else // Unmute the volume |
|
166 { |
|
167 iCurrentVolume = iPreviousVolume; |
|
168 } |
|
169 } |
|
170 |
|
171 // Tell observer the new volume |
|
172 if ( iObserver ) |
|
173 { |
|
174 iObserver->UpdateVolume( iCurrentVolume ); |
|
175 } |
|
176 } |
|
177 |
|
178 // End of file |