|
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: Wrapper for mpx framework utilities. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QTranslator> |
|
19 #include <QLocale> |
|
20 #include <hbmessagebox.h> |
|
21 #include <hbnotificationdialog.h> |
|
22 #include <hbinstance.h> |
|
23 |
|
24 #include "mpengine.h" |
|
25 #include "mpmpxframeworkwrapper.h" |
|
26 #include "mpsongscanner.h" |
|
27 #include "mpmediakeyhandler.h" |
|
28 #include "mptrace.h" |
|
29 |
|
30 /*! |
|
31 \class MpEngine |
|
32 \brief Engine for musicplayer - mpx framework utilities. |
|
33 |
|
34 MP Engine provides Qt style interface to the MPX framework |
|
35 utilities. Its implementation is hidden using private class data pattern. |
|
36 */ |
|
37 |
|
38 /*! |
|
39 \fn void scanStarted() |
|
40 |
|
41 This signal is emitted when scan operation is started. |
|
42 |
|
43 */ |
|
44 |
|
45 /*! |
|
46 \fn void scanEnded() |
|
47 |
|
48 This signal is emitted when scan operation ends. |
|
49 |
|
50 */ |
|
51 |
|
52 /*! |
|
53 \fn void scanCountChanged( int count ) |
|
54 |
|
55 This signal is emitted when scan count is updated. |
|
56 |
|
57 */ |
|
58 |
|
59 /*! |
|
60 \fn void libraryRefreshed() |
|
61 |
|
62 This signal is emitted when MpSongScannerHelper ends scanning, |
|
63 or USB-MTP Synchronization finishes. |
|
64 |
|
65 */ |
|
66 |
|
67 /*! |
|
68 \fn void formatStarted() |
|
69 |
|
70 This signal is emitted when EMcMsgFormatStart is received from MPXCollectionUtility. |
|
71 |
|
72 */ |
|
73 |
|
74 /*! |
|
75 \fn void formatEnded() |
|
76 |
|
77 This signal is emitted when EMcMsgFormatEnd is received from MPXCollectionUtility. |
|
78 |
|
79 */ |
|
80 |
|
81 /*! |
|
82 \fn void diskRemoved() |
|
83 |
|
84 This signal is emitted when EMcMsgDiskRemoved is received from MPXCollectionUtility. |
|
85 |
|
86 */ |
|
87 |
|
88 /*! |
|
89 \fn void diskInserted() |
|
90 |
|
91 This signal is emitted when EMcMsgDiskInserted is received from MPXCollectionUtility. |
|
92 |
|
93 */ |
|
94 |
|
95 /*! |
|
96 \fn void usbMassStorageStarted() |
|
97 |
|
98 This signal is emitted when EMcMsgUSBMassStorageStart is received from MPXCollectionUtility. |
|
99 |
|
100 */ |
|
101 |
|
102 /*! |
|
103 \fn void usbMassStorageEnded() |
|
104 |
|
105 This signal is emitted when EMcMsgUSBMassStorageEnd is received from MPXCollectionUtility. |
|
106 |
|
107 */ |
|
108 |
|
109 /*! |
|
110 \fn void usbMtpStarted() |
|
111 |
|
112 This signal is emitted when EMcMsgUSBMtpStart is received from MPXCollectionUtility. |
|
113 |
|
114 */ |
|
115 |
|
116 /*! |
|
117 \fn void usbMtpEnded() |
|
118 |
|
119 This signal is emitted when EMcMsgUSBMtpEnd is received from MPXCollectionUtility. |
|
120 |
|
121 */ |
|
122 |
|
123 /*! |
|
124 Constructs music player engine. |
|
125 */ |
|
126 MpEngine::MpEngine() |
|
127 : mMpxWrapper(0), |
|
128 mSongScanner(0), |
|
129 mMediaKeyHandler(0), |
|
130 mUsbBlockingNote(0), |
|
131 mMpTranslator(0), |
|
132 mUsbBlockingState(USB_NotConnected), |
|
133 mPreviousUsbState(USB_NotConnected) |
|
134 { |
|
135 TX_ENTRY |
|
136 |
|
137 mMpxWrapper = new MpMpxFrameworkWrapper(); |
|
138 connect( mMpxWrapper, SIGNAL( scanStarted() ), this, SLOT( handleScanStarted() ) ); |
|
139 connect( mMpxWrapper, SIGNAL( scanEnded(int, int) ), this, SLOT( handleScanEnded(int, int) ) ); |
|
140 connect( mMpxWrapper, SIGNAL( diskEvent(MpxDiskEvents) ), this, SLOT( handleDiskEvent(MpxDiskEvents) ) ); |
|
141 connect( mMpxWrapper, SIGNAL( usbEvent(MpxUsbEvents) ), this, SLOT( handleUsbEvent(MpxUsbEvents) ) ); |
|
142 |
|
143 mSongScanner = new MpSongScanner( mMpxWrapper ); |
|
144 mMediaKeyHandler = new MpMediaKeyHandler(); |
|
145 |
|
146 //Load musicplayer translator |
|
147 QString lang = QLocale::system().name(); |
|
148 QString path = QString( "z:/resource/qt/translations/" ); |
|
149 bool translatorLoaded = false; |
|
150 |
|
151 mMpTranslator = new QTranslator( this ); |
|
152 translatorLoaded = mMpTranslator->load( path + "musicplayer_" + lang ); |
|
153 TX_LOG_ARGS( "Loading translator ok=" << translatorLoaded ); |
|
154 if ( translatorLoaded ) { |
|
155 qApp->installTranslator( mMpTranslator ); |
|
156 } |
|
157 |
|
158 TX_EXIT |
|
159 } |
|
160 |
|
161 /*! |
|
162 Destructs music player engine. |
|
163 */ |
|
164 MpEngine::~MpEngine() |
|
165 { |
|
166 TX_ENTRY |
|
167 delete mMpTranslator; |
|
168 delete mSongScanner; |
|
169 delete mMediaKeyHandler; |
|
170 delete mUsbBlockingNote; |
|
171 TX_EXIT |
|
172 } |
|
173 |
|
174 /*! |
|
175 Returns the singleton instance of music player engine. |
|
176 */ |
|
177 MpEngine * MpEngine::instance() |
|
178 { |
|
179 static MpEngine instance; |
|
180 return &instance; |
|
181 } |
|
182 |
|
183 /*! |
|
184 Refresh library by starting the scan. |
|
185 If scanning is already ongoing, this request is ignored. |
|
186 */ |
|
187 void MpEngine::refreshLibrary() |
|
188 { |
|
189 TX_ENTRY |
|
190 emit libraryAboutToRefresh(); |
|
191 mSongScanner->scan(); |
|
192 TX_EXIT |
|
193 } |
|
194 |
|
195 /*! |
|
196 \ |
|
197 Used to verify if an action can be executed depending on USB blocking state. |
|
198 If not, a notification note might be displayed. |
|
199 */ |
|
200 bool MpEngine::verifyUsbBlocking( bool showMessage ) |
|
201 { |
|
202 TX_ENTRY |
|
203 bool result( false ); |
|
204 if ( mUsbBlockingState == USB_Connected ) { |
|
205 result = true; |
|
206 if ( showMessage ) { |
|
207 HbMessageBox dialog ( HbMessageBox::MessageTypeInformation ); |
|
208 dialog.setText( QString( tr( "USB connection in progress. Cannot proceed with operation" ) ) ); |
|
209 dialog.setModal( true ); |
|
210 dialog.exec(); |
|
211 } |
|
212 } |
|
213 TX_EXIT |
|
214 return result; |
|
215 } |
|
216 |
|
217 /*! |
|
218 Slot to be called when song scanning starts. |
|
219 */ |
|
220 void MpEngine::handleScanStarted() { |
|
221 TX_ENTRY |
|
222 mMediaKeyHandler->setEnabled(false); |
|
223 TX_EXIT |
|
224 } |
|
225 |
|
226 /*! |
|
227 Slot to be called when song scanning ends. |
|
228 */ |
|
229 void MpEngine::handleScanEnded( int count, int error ) { |
|
230 TX_ENTRY |
|
231 Q_UNUSED( count ); |
|
232 Q_UNUSED( error ); |
|
233 mMediaKeyHandler->setEnabled(true); |
|
234 emit libraryRefreshed(); |
|
235 TX_EXIT |
|
236 } |
|
237 |
|
238 /*! |
|
239 Slot to be called when disk event is received from MPX framework. |
|
240 */ |
|
241 void MpEngine::handleDiskEvent( MpxDiskEvents event ) |
|
242 { |
|
243 TX_ENTRY_ARGS("event=" << event); |
|
244 switch ( event ) { |
|
245 case DiskFormatStarted: |
|
246 mMediaKeyHandler->setEnabled(false); |
|
247 break; |
|
248 case DiskFormatEnded: |
|
249 mMediaKeyHandler->setEnabled(true); |
|
250 break; |
|
251 case DiskRemoved: |
|
252 if ( mUsbBlockingState == USB_NotConnected ) { |
|
253 emit exitApplication(); |
|
254 } |
|
255 break; |
|
256 case DiskInserted: |
|
257 if ( mUsbBlockingState == USB_NotConnected ) { |
|
258 refreshLibrary(); |
|
259 } |
|
260 break; |
|
261 default: |
|
262 break; |
|
263 } |
|
264 TX_EXIT |
|
265 } |
|
266 |
|
267 /*! |
|
268 Slot to be called when USB event is received from MPX framework. |
|
269 */ |
|
270 void MpEngine::handleUsbEvent( MpxUsbEvents event ) |
|
271 { |
|
272 TX_ENTRY_ARGS("event=" << event); |
|
273 switch ( event ) { |
|
274 case UsbMassStorageStarted: |
|
275 handleUsbMassStorageStartEvent(); |
|
276 break; |
|
277 case UsbMassStorageEnded: |
|
278 handleUsbMassStorageEndEvent(); |
|
279 break; |
|
280 case UsbMtpStarted: |
|
281 handleUsbMtpStartEvent(); |
|
282 break; |
|
283 case UsbMtpEnded: |
|
284 handleUsbMtpEndEvent(); |
|
285 break; |
|
286 case UsbMtpNotActive: |
|
287 handleUsbMtpNotActive(); |
|
288 default: |
|
289 break; |
|
290 } |
|
291 TX_EXIT |
|
292 } |
|
293 |
|
294 /*! |
|
295 To be called when EMcMsgUSBMassStorageStart event is received. |
|
296 */ |
|
297 void MpEngine::handleUsbMassStorageStartEvent() |
|
298 { |
|
299 TX_ENTRY |
|
300 mMediaKeyHandler->setEnabled(false); |
|
301 |
|
302 changeUsbBlockingState( USB_Synchronizing ); |
|
303 emit usbBlocked(true); |
|
304 |
|
305 if ( !mUsbBlockingNote ) { |
|
306 mUsbBlockingNote = new HbNotificationDialog(); |
|
307 mUsbBlockingNote->setText( QString( tr( "USB connection in progress" ) ) ); |
|
308 mUsbBlockingNote->setModal( true ); |
|
309 mUsbBlockingNote->setTimeout( HbPopup::NoTimeout ); |
|
310 } |
|
311 mUsbBlockingNote->show(); |
|
312 TX_EXIT |
|
313 } |
|
314 |
|
315 /*! |
|
316 To be called when EMcMsgUSBMassStorageEnd event is received. |
|
317 */ |
|
318 void MpEngine::handleUsbMassStorageEndEvent() |
|
319 { |
|
320 TX_ENTRY |
|
321 mMediaKeyHandler->setEnabled(true); |
|
322 |
|
323 changeUsbBlockingState( USB_NotConnected ); |
|
324 emit usbBlocked(false); |
|
325 |
|
326 if ( mUsbBlockingNote ) { |
|
327 delete mUsbBlockingNote; |
|
328 mUsbBlockingNote = 0; |
|
329 } |
|
330 HbMessageBox promptRefresh( HbMessageBox::MessageTypeQuestion ); |
|
331 promptRefresh.setText( QString( tr( "List may need refreshing due to recent USB synchronisation. Refresh now?" ) ) ); |
|
332 promptRefresh.setTimeout( HbPopup::NoTimeout ); |
|
333 promptRefresh.setModal( true ); |
|
334 HbAction *action = promptRefresh.exec(); |
|
335 if ( action == promptRefresh.primaryAction() ) { |
|
336 refreshLibrary(); |
|
337 } |
|
338 TX_EXIT |
|
339 } |
|
340 |
|
341 /*! |
|
342 To be called when EMcMsgUSBMTPStart event is received. |
|
343 */ |
|
344 void MpEngine::handleUsbMtpStartEvent() |
|
345 { |
|
346 TX_ENTRY |
|
347 mMediaKeyHandler->setEnabled(false); |
|
348 |
|
349 changeUsbBlockingState( USB_Synchronizing ); |
|
350 emit usbBlocked(true); |
|
351 |
|
352 if ( !mUsbBlockingNote ) { |
|
353 mUsbBlockingNote = new HbNotificationDialog(); |
|
354 mUsbBlockingNote->setText( QString( tr( "USB connection in progress" ) ) ); |
|
355 mUsbBlockingNote->setModal( true ); |
|
356 mUsbBlockingNote->setTimeout( HbPopup::NoTimeout ); |
|
357 } |
|
358 mUsbBlockingNote->show(); |
|
359 TX_EXIT |
|
360 } |
|
361 |
|
362 /*! |
|
363 To be called when EMcMsgUSBMTPEnd event is received. |
|
364 */ |
|
365 void MpEngine::handleUsbMtpEndEvent() |
|
366 { |
|
367 TX_ENTRY |
|
368 mMediaKeyHandler->setEnabled(true); |
|
369 |
|
370 changeUsbBlockingState( USB_NotConnected ); |
|
371 emit usbBlocked(false); |
|
372 |
|
373 if ( mUsbBlockingNote ) { |
|
374 delete mUsbBlockingNote; |
|
375 mUsbBlockingNote = 0; |
|
376 } |
|
377 if ( mPreviousUsbState == USB_Synchronizing ) { |
|
378 emit libraryRefreshed(); |
|
379 } |
|
380 TX_EXIT |
|
381 } |
|
382 |
|
383 /*! |
|
384 To be called when EMcMsgUSBMTPNotActive event is received. |
|
385 */ |
|
386 void MpEngine::handleUsbMtpNotActive() |
|
387 { |
|
388 TX_ENTRY |
|
389 |
|
390 changeUsbBlockingState( USB_Connected ); |
|
391 emit usbBlocked(true); |
|
392 |
|
393 TX_EXIT |
|
394 } |
|
395 |
|
396 /*! |
|
397 Internal |
|
398 Update the new and previous usb blocking state |
|
399 */ |
|
400 void MpEngine::changeUsbBlockingState( UsbBlockingState state ) |
|
401 { |
|
402 TX_ENTRY |
|
403 |
|
404 mPreviousUsbState = mUsbBlockingState; |
|
405 mUsbBlockingState = state; |
|
406 |
|
407 TX_EXIT |
|
408 } |