|
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 Playback view. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <qpainter> |
|
19 #include <qtgui> |
|
20 |
|
21 #include <hbmenu.h> |
|
22 #include <hbinstance.h> |
|
23 #include <hbtoolbar.h> |
|
24 #include <hbaction.h> |
|
25 #include <hbicon.h> |
|
26 |
|
27 #include "mpplaybackview.h" |
|
28 #include "mpplaybackwidget.h" |
|
29 #include "mpmpxpbframeworkwrapper.h" |
|
30 #include "mpplaybackdata.h" |
|
31 #include "mpsettingsmanager.h" |
|
32 #include "mpcommondefs.h" |
|
33 #include "mptrace.h" |
|
34 |
|
35 |
|
36 /*! |
|
37 \class MpPlaybackView |
|
38 \brief Music Player playback view. |
|
39 |
|
40 Playback view provides access to music playback in the device. |
|
41 This class owns the menu and the toolbar. In addition, it is |
|
42 responsible for creating UI widgets and the underlying engine |
|
43 components and connecting them to work together. |
|
44 */ |
|
45 |
|
46 /*! |
|
47 \fn void command( int command ) |
|
48 |
|
49 This signal is emitted when the view issues a \a command to the |
|
50 application such as request to switch to a different view. |
|
51 */ |
|
52 |
|
53 /*! |
|
54 Constructs the playback view. |
|
55 */ |
|
56 MpPlaybackView::MpPlaybackView() |
|
57 : mFrameworkWrapper(0), |
|
58 mPlaybackData(0), |
|
59 mPlaybackWidget(0), |
|
60 mSoftKeyBack(0), |
|
61 mActivated(false), |
|
62 mPlayIcon(0), |
|
63 mPauseIcon(0), |
|
64 mShuffleOnIcon(0), |
|
65 mShuffleOffIcon(0) |
|
66 { |
|
67 TX_LOG |
|
68 } |
|
69 |
|
70 /*! |
|
71 Destructs the playback view. |
|
72 */ |
|
73 MpPlaybackView::~MpPlaybackView() |
|
74 { |
|
75 TX_ENTRY |
|
76 delete mFrameworkWrapper; |
|
77 delete mSoftKeyBack; |
|
78 delete mPlayIcon; |
|
79 delete mPauseIcon; |
|
80 delete mShuffleOnIcon; |
|
81 delete mShuffleOffIcon; |
|
82 TX_EXIT |
|
83 } |
|
84 |
|
85 |
|
86 /*! |
|
87 Initializes the playback view. |
|
88 */ |
|
89 void MpPlaybackView::initializeView() |
|
90 { |
|
91 TX_ENTRY |
|
92 |
|
93 mWindow = mainWindow(); |
|
94 |
|
95 mSoftKeyBack = new HbAction(Hb::BackAction, this); |
|
96 connect( mSoftKeyBack, SIGNAL(triggered()), this, SLOT(back()) ); |
|
97 |
|
98 mFrameworkWrapper = new MpMpxPbFrameworkWrapper(); |
|
99 mPlaybackData = mFrameworkWrapper->playbackData(); |
|
100 connect( mPlaybackData, SIGNAL(playbackStateChanged()), |
|
101 this, SLOT(playbackStateChanged()) ); |
|
102 |
|
103 mPlaybackWidget = new MpPlaybackWidget(mPlaybackData); |
|
104 connect( mPlaybackWidget, SIGNAL(setPlaybackPosition(int)), mFrameworkWrapper, SLOT( setPosition(int) ) ); |
|
105 |
|
106 setWidget(mPlaybackWidget); |
|
107 setupMenu(); |
|
108 setupToolbar(); |
|
109 |
|
110 // Observe changes in settings. |
|
111 connect( MpSettingsManager::instance(), SIGNAL(shuffleChanged(bool)), |
|
112 this, SLOT(shuffleChanged(bool)) ); |
|
113 connect( MpSettingsManager::instance(), SIGNAL(repeatChanged(bool)), |
|
114 this, SLOT(repeatChanged(bool)) ); |
|
115 |
|
116 TX_EXIT |
|
117 } |
|
118 |
|
119 /*! |
|
120 Activates the playback view. |
|
121 */ |
|
122 void MpPlaybackView::activateView() |
|
123 { |
|
124 TX_ENTRY |
|
125 mActivated = true; |
|
126 mWindow->addSoftKeyAction(Hb::SecondarySoftKey, mSoftKeyBack); |
|
127 TX_EXIT |
|
128 } |
|
129 |
|
130 /*! |
|
131 Deactivates the playback view. |
|
132 */ |
|
133 void MpPlaybackView::deactivateView() |
|
134 { |
|
135 TX_ENTRY |
|
136 mWindow->removeSoftKeyAction(Hb::SecondarySoftKey, mSoftKeyBack); |
|
137 mActivated = false; |
|
138 TX_EXIT |
|
139 } |
|
140 |
|
141 /*! |
|
142 Slot to be called to activate collection view. |
|
143 */ |
|
144 void MpPlaybackView::startCollectionView() |
|
145 { |
|
146 TX_LOG |
|
147 emit command( MpCommon::ActivateCollectionView ); |
|
148 } |
|
149 |
|
150 /*! |
|
151 Slot to handle back command from softkey. |
|
152 */ |
|
153 void MpPlaybackView::back() |
|
154 { |
|
155 TX_ENTRY |
|
156 // Stop the playback preview when returning to collection in fetch mode |
|
157 if ( mViewMode == MpCommon::FetchView ) { |
|
158 mFrameworkWrapper->stop(); |
|
159 } |
|
160 emit command( MpCommon::ActivateCollectionView ); |
|
161 TX_EXIT |
|
162 } |
|
163 |
|
164 /*! |
|
165 Slot to be called to exit. |
|
166 */ |
|
167 void MpPlaybackView::exit() |
|
168 { |
|
169 TX_ENTRY |
|
170 emit command( MpCommon::Exit ); |
|
171 TX_EXIT |
|
172 } |
|
173 |
|
174 /*! |
|
175 Slot to handle playback state changed. |
|
176 */ |
|
177 void MpPlaybackView::playbackStateChanged( ) |
|
178 { |
|
179 TX_ENTRY |
|
180 switch ( mPlaybackData->playbackState() ) { |
|
181 case MpPlaybackData::Playing: |
|
182 TX_LOG_ARGS("MpPlaybackData::Playing") |
|
183 mPlayPauseAction->setIcon( *mPauseIcon ); |
|
184 break; |
|
185 case MpPlaybackData::Paused: |
|
186 TX_LOG_ARGS("MpPlaybackData::Paused") |
|
187 mPlayPauseAction->setIcon( *mPlayIcon ); |
|
188 break; |
|
189 case MpPlaybackData::Stopped: |
|
190 TX_LOG_ARGS("MpPlaybackData::Paused") |
|
191 if ( mViewMode == MpCommon::FetchView ) { |
|
192 back(); |
|
193 } |
|
194 else { |
|
195 // Treat it like pause in default mode |
|
196 mPlayPauseAction->setIcon( *mPlayIcon ); |
|
197 } |
|
198 break; |
|
199 default: |
|
200 break; |
|
201 } |
|
202 TX_EXIT |
|
203 } |
|
204 |
|
205 /*! |
|
206 Slot to handle shuffle toggle. |
|
207 */ |
|
208 void MpPlaybackView::toggleShuffle() |
|
209 { |
|
210 mFrameworkWrapper->setShuffle( !mShuffle ); |
|
211 MpSettingsManager::setShuffle(!mShuffle); |
|
212 } |
|
213 |
|
214 /*! |
|
215 Slot to handle /a shuffle setting change. |
|
216 */ |
|
217 void MpPlaybackView::shuffleChanged( bool shuffle ) |
|
218 { |
|
219 mShuffle = shuffle; |
|
220 mShuffleAction->setIcon( mShuffle ? *mShuffleOnIcon : *mShuffleOffIcon); |
|
221 } |
|
222 |
|
223 /*! |
|
224 Slot to handle repeat toggle. |
|
225 */ |
|
226 void MpPlaybackView::toggleRepeat() |
|
227 { |
|
228 mFrameworkWrapper->setRepeat(!mRepeat); |
|
229 MpSettingsManager::setRepeat(!mRepeat); |
|
230 } |
|
231 |
|
232 /*! |
|
233 Slot to handle /a repeat setting change. |
|
234 */ |
|
235 void MpPlaybackView::repeatChanged(bool repeat) |
|
236 { |
|
237 mRepeat = repeat; |
|
238 mRepeatAction->setText( mRepeat ? tr("Repeat off") : tr("Repeat on")); |
|
239 } |
|
240 |
|
241 /*! |
|
242 Slot called when a song is selected in fetch mode. |
|
243 */ |
|
244 void MpPlaybackView::handleSongSelected() |
|
245 { |
|
246 TX_ENTRY |
|
247 mFrameworkWrapper->stop(); |
|
248 emit songSelected( mPlaybackData->uri() ); |
|
249 TX_EXIT |
|
250 } |
|
251 |
|
252 /*! |
|
253 setup the menu. |
|
254 */ |
|
255 void MpPlaybackView::setupMenu() |
|
256 { |
|
257 TX_ENTRY |
|
258 if ( mViewMode == MpCommon::DefaultView ) { |
|
259 mRepeat = MpSettingsManager::repeat(); |
|
260 HbMenu* myMenu = new HbMenu(); |
|
261 connect( myMenu->addAction(tr("Go to music library")), SIGNAL(triggered()), this, SLOT(startCollectionView()) ); |
|
262 mRepeatAction = myMenu->addAction( mRepeat ? tr("Repeat off") : tr("Repeat on")); |
|
263 connect( mRepeatAction , SIGNAL(triggered()), this, SLOT(toggleRepeat()) ); |
|
264 connect( myMenu->addAction(tr("Exit")), SIGNAL(triggered()), this, SLOT(exit()) ); |
|
265 setMenu(myMenu); |
|
266 } |
|
267 TX_EXIT |
|
268 } |
|
269 |
|
270 /*! |
|
271 setup the toolbar. |
|
272 */ |
|
273 void MpPlaybackView::setupToolbar() |
|
274 { |
|
275 TX_ENTRY |
|
276 HbToolBar *toolBar = this->toolBar(); |
|
277 toolBar->setOrientation(Qt::Horizontal); |
|
278 QActionGroup *actionsGroup = new QActionGroup( toolBar ); |
|
279 |
|
280 if ( mViewMode == MpCommon::DefaultView ) { |
|
281 mShuffleOnIcon = new HbIcon(":/playbackviewicons/shuffle_on.svg"); |
|
282 mShuffleOffIcon = new HbIcon( ":/playbackviewicons/shuffle_off.svg"); |
|
283 mShuffleAction = new HbAction(actionsGroup); |
|
284 mShuffle = MpSettingsManager::shuffle(); |
|
285 mShuffleAction->setIcon( mShuffle ? *mShuffleOnIcon : *mShuffleOffIcon); |
|
286 mShuffleAction->setCheckable( false ); |
|
287 |
|
288 connect( mShuffleAction, SIGNAL(triggered(bool)), |
|
289 this, SLOT(toggleShuffle()) ); |
|
290 toolBar->addAction( mShuffleAction ); |
|
291 |
|
292 HbAction *action = new HbAction(actionsGroup); |
|
293 action->setIcon( HbIcon( ":/playbackviewicons/prev.svg") ); |
|
294 action->setCheckable( false ); |
|
295 connect( action, SIGNAL(triggered(bool)), |
|
296 mFrameworkWrapper, SLOT(skipBackward()) ); |
|
297 toolBar->addAction( action ); |
|
298 |
|
299 mPlayPauseAction = new HbAction(actionsGroup); |
|
300 mPlayIcon = new HbIcon(":/playbackviewicons/play.svg"); |
|
301 mPauseIcon = new HbIcon( ":/playbackviewicons/pause.svg" ); |
|
302 mPlayPauseAction->setIcon( *mPlayIcon ); |
|
303 mPlayPauseAction->setCheckable( false ); |
|
304 connect( mPlayPauseAction, SIGNAL(triggered(bool)), |
|
305 mFrameworkWrapper, SLOT(playPause()) ); |
|
306 toolBar->addAction( mPlayPauseAction ); |
|
307 |
|
308 action = new HbAction(actionsGroup); |
|
309 action->setIcon( HbIcon(":/playbackviewicons/next.svg") ); |
|
310 action->setCheckable( false ); |
|
311 connect( action, SIGNAL(triggered(bool)), |
|
312 mFrameworkWrapper, SLOT(skipForward()) ); |
|
313 toolBar->addAction( action ); |
|
314 |
|
315 HbIcon icon( ":/playbackviewicons/info.svg" ); |
|
316 action = new HbAction(actionsGroup); |
|
317 action->setIcon( icon ); |
|
318 action->setCheckable( false ); |
|
319 /* |
|
320 connect( action, SIGNAL(triggered(bool)), |
|
321 this, SLOT( flip()) ); |
|
322 */ |
|
323 toolBar->addAction( action ); |
|
324 } |
|
325 else { |
|
326 // Fetch mode |
|
327 HbAction *action = new HbAction(actionsGroup); |
|
328 action->setIcon( HbIcon(":/playbackviewicons/select.png") ); |
|
329 action->setCheckable( false ); |
|
330 connect( action, SIGNAL(triggered(bool)), |
|
331 this, SLOT(handleSongSelected()) ); |
|
332 toolBar->addAction( action ); |
|
333 |
|
334 mPlayPauseAction = new HbAction(actionsGroup); |
|
335 mPlayIcon = new HbIcon(":/playbackviewicons/play.svg"); |
|
336 mPauseIcon = new HbIcon( ":/playbackviewicons/pause.svg" ); |
|
337 mPlayPauseAction->setIcon( *mPlayIcon ); |
|
338 mPlayPauseAction->setCheckable( false ); |
|
339 connect( mPlayPauseAction, SIGNAL(triggered(bool)), |
|
340 mFrameworkWrapper, SLOT(playPause()) ); |
|
341 toolBar->addAction( mPlayPauseAction ); |
|
342 } |
|
343 TX_EXIT |
|
344 } |
|
345 |