47
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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: Music Player volume slider.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <hbvolumesliderpopup.h>
|
|
19 |
|
|
20 |
#include "mpvolumeslider.h"
|
|
21 |
#include "mpenginefactory.h"
|
|
22 |
#include "mptrace.h"
|
|
23 |
|
|
24 |
const int KVolumeMin = 0;
|
|
25 |
const int KVolumeMuted = 1;
|
|
26 |
const int KDefaultSteps = 10;
|
|
27 |
const int KDataCompleted = 0x07; // 0x01 volume max, 0x02 volume level, 0x04 volume mute
|
|
28 |
|
|
29 |
/*!
|
|
30 |
Constructs MpVolumeSlider.
|
|
31 |
*/
|
|
32 |
MpVolumeSlider::MpVolumeSlider( QObject *parent )
|
|
33 |
: QObject( parent),
|
|
34 |
mMpEngine( 0 ),
|
|
35 |
mVolumeSliderPopup( 0 ),
|
|
36 |
mEngineVolumeMax( 0 ),
|
|
37 |
mEngineVolumeLevel( 0 ),
|
|
38 |
mEngineMuted( false ),
|
|
39 |
mEngineDataCompleted( 0 ),
|
|
40 |
mSliderPressed( false ),
|
|
41 |
mSliderStep( 0 )
|
|
42 |
{
|
|
43 |
TX_ENTRY
|
|
44 |
mMpEngine = MpEngineFactory::sharedEngine();
|
|
45 |
connect( mMpEngine, SIGNAL( volumePropertyChanged( MpCommon::MpVolumeProperty, int ) ),
|
|
46 |
this, SLOT( handleVolumeProperty( MpCommon::MpVolumeProperty, int ) ) );
|
|
47 |
|
|
48 |
//Request Volume properties
|
|
49 |
mMpEngine->getMaxVolume();
|
|
50 |
mMpEngine->getVolume();
|
|
51 |
mMpEngine->getMuteState();
|
|
52 |
TX_EXIT
|
|
53 |
}
|
|
54 |
|
|
55 |
/*!
|
|
56 |
Destructs MpVolumeSlider.
|
|
57 |
*/
|
|
58 |
MpVolumeSlider::~MpVolumeSlider()
|
|
59 |
{
|
|
60 |
TX_ENTRY
|
|
61 |
delete mVolumeSliderPopup;
|
|
62 |
TX_EXIT
|
|
63 |
}
|
|
64 |
|
|
65 |
/*!
|
|
66 |
Make volume slider visible with latest engine data.
|
|
67 |
*/
|
|
68 |
void MpVolumeSlider::showVolumeSlider()
|
|
69 |
{
|
|
70 |
TX_ENTRY
|
|
71 |
|
|
72 |
if ( !mSliderPressed ) {
|
|
73 |
|
|
74 |
// Initialize popup until needed, in order to save time during app start up.
|
|
75 |
if ( !mVolumeSliderPopup ) {
|
|
76 |
initializeVolumeSliderPopup();
|
|
77 |
}
|
|
78 |
|
|
79 |
// Update VolumeSlider with Engine values
|
|
80 |
if ( mEngineMuted ) {
|
|
81 |
if ( mVolumeSliderPopup->value() != KVolumeMin ) {
|
|
82 |
// Muted from outside (possibly from Headset or MediaKeys), update volume slider as "muted"
|
|
83 |
// Todo: Replace with a more appropriate method to mute slider, when provided by Orbit.
|
|
84 |
mVolumeSliderPopup->setValue( KVolumeMin );
|
|
85 |
}
|
|
86 |
}
|
|
87 |
else if ( mVolumeSliderPopup->value() != ( mEngineVolumeLevel / mSliderStep ) ){
|
|
88 |
mVolumeSliderPopup->setValue( mEngineVolumeLevel / mSliderStep );
|
|
89 |
}
|
|
90 |
|
|
91 |
// Show VolumeSlider
|
|
92 |
if ( !mVolumeSliderPopup->isVisible() ) {
|
|
93 |
mVolumeSliderPopup->setVisible( true );
|
|
94 |
}
|
|
95 |
}
|
|
96 |
|
|
97 |
TX_EXIT
|
|
98 |
}
|
|
99 |
|
|
100 |
/*!
|
|
101 |
Slot to handle volume property notifications
|
|
102 |
*/
|
|
103 |
void MpVolumeSlider::handleVolumeProperty( MpCommon::MpVolumeProperty property, int value )
|
|
104 |
{
|
|
105 |
TX_ENTRY_ARGS("Property: " << property << ", Value: " << value );
|
|
106 |
switch( property )
|
|
107 |
{
|
|
108 |
case MpCommon::MaxVolume :
|
|
109 |
mEngineVolumeMax = value;
|
|
110 |
mEngineDataCompleted |= 0x01;
|
|
111 |
break;
|
|
112 |
case MpCommon::Volume :
|
|
113 |
mEngineVolumeLevel = value;
|
|
114 |
// Framework automatically mutes if volume == KVolumeMin and unmutes when volume > KVolumeMin
|
|
115 |
mEngineMuted = mEngineVolumeLevel == KVolumeMin;
|
|
116 |
if ( mEngineDataCompleted == KDataCompleted ) {
|
|
117 |
showVolumeSlider();
|
|
118 |
}
|
|
119 |
else {
|
|
120 |
mEngineDataCompleted |= 0x02;
|
|
121 |
}
|
|
122 |
break;
|
|
123 |
case MpCommon::MuteState :
|
|
124 |
mEngineMuted = ( value == KVolumeMuted );
|
|
125 |
if ( mEngineDataCompleted == KDataCompleted ) {
|
|
126 |
showVolumeSlider();
|
|
127 |
}
|
|
128 |
else {
|
|
129 |
mEngineDataCompleted |= 0x04;
|
|
130 |
}
|
|
131 |
break;
|
|
132 |
default:
|
|
133 |
TX_LOG_ARGS( "We should never be here" );
|
|
134 |
break;
|
|
135 |
}
|
|
136 |
TX_EXIT
|
|
137 |
}
|
|
138 |
|
|
139 |
/*!
|
|
140 |
Slot called when slider is pressed.
|
|
141 |
*/
|
|
142 |
void MpVolumeSlider::sliderPressed()
|
|
143 |
{
|
|
144 |
TX_ENTRY
|
|
145 |
mSliderPressed = true;
|
|
146 |
TX_EXIT
|
|
147 |
}
|
|
148 |
|
|
149 |
/*!
|
|
150 |
Slot called when slider is released.
|
|
151 |
*/
|
|
152 |
void MpVolumeSlider::sliderReleased()
|
|
153 |
{
|
|
154 |
TX_ENTRY
|
|
155 |
mSliderPressed = false;
|
|
156 |
TX_EXIT
|
|
157 |
}
|
|
158 |
|
|
159 |
/*!
|
|
160 |
Slot called when mute icon is clicekd.
|
|
161 |
*/
|
|
162 |
void MpVolumeSlider::muteIconClicked()
|
|
163 |
{
|
|
164 |
TX_ENTRY
|
|
165 |
if ( mVolumeSliderPopup->value() ) {
|
|
166 |
mMpEngine->unmute();
|
|
167 |
mEngineMuted = false;
|
|
168 |
}
|
|
169 |
else {
|
|
170 |
mMpEngine->mute();
|
|
171 |
mEngineMuted = true;
|
|
172 |
}
|
|
173 |
TX_EXIT
|
|
174 |
}
|
|
175 |
|
|
176 |
/*!
|
|
177 |
Slot called when volume slider value changes.
|
|
178 |
*/
|
|
179 |
void MpVolumeSlider::volumeSliderChanged( int value )
|
|
180 |
{
|
|
181 |
TX_ENTRY
|
|
182 |
|
|
183 |
if ( mEngineVolumeLevel != ( value * mSliderStep ) ) {
|
|
184 |
// When Mute icon is clicked, slider value changes automatically to zero,
|
|
185 |
// don't send that change in order to avoid reset the engine previous volume.
|
|
186 |
if ( !( mEngineMuted && value == KVolumeMin ) ) {
|
|
187 |
mMpEngine->setVolume( value * mSliderStep );
|
|
188 |
}
|
|
189 |
}
|
|
190 |
|
|
191 |
TX_EXIT
|
|
192 |
}
|
|
193 |
|
|
194 |
/*!
|
|
195 |
Inernal
|
|
196 |
*/
|
|
197 |
void MpVolumeSlider::initializeVolumeSliderPopup()
|
|
198 |
{
|
|
199 |
TX_ENTRY
|
|
200 |
|
|
201 |
mVolumeSliderPopup = new HbVolumeSliderPopup();
|
|
202 |
mVolumeSliderPopup->setRange( KVolumeMin, KDefaultSteps );
|
|
203 |
mVolumeSliderPopup->setSingleStep( 1 );
|
|
204 |
mVolumeSliderPopup->setTickPosition( Hb::NoSliderTicks );
|
|
205 |
mSliderStep = mEngineVolumeMax / KDefaultSteps ;
|
|
206 |
|
|
207 |
connect( mVolumeSliderPopup, SIGNAL( sliderPressed() ),
|
|
208 |
this, SLOT( sliderPressed() ) );
|
|
209 |
connect( mVolumeSliderPopup, SIGNAL( sliderReleased() ),
|
|
210 |
this, SLOT( sliderReleased() ) );
|
|
211 |
connect( mVolumeSliderPopup, SIGNAL( iconClicked() ),
|
|
212 |
this, SLOT( muteIconClicked() ) );
|
|
213 |
// volumeChanged event is also sent when VolumeSlider is Muted/Unmuted
|
|
214 |
// QueuedConnection used in order to handle Mute events first,
|
|
215 |
// and then be able to know whether to apply the slider volume changes to the engine
|
|
216 |
connect( mVolumeSliderPopup, SIGNAL( valueChanged( int ) ),
|
|
217 |
this, SLOT( volumeSliderChanged( int ) ),
|
|
218 |
Qt::QueuedConnection );
|
|
219 |
|
|
220 |
TX_EXIT
|
|
221 |
}
|
|
222 |
|