37
|
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 global popup handler.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// INCLUDE FILES
|
|
19 |
#include <hblabel.h>
|
|
20 |
#include <hbaction.h>
|
|
21 |
#include <hbfontspec.h>
|
|
22 |
#include <hbmessagebox.h>
|
|
23 |
#include <hbprogressdialog.h>
|
|
24 |
#include <hbnotificationdialog.h>
|
|
25 |
|
|
26 |
#include "mpglobalpopuphandler.h"
|
|
27 |
#include "mpsettingsmanager.h"
|
|
28 |
#include "mpenginefactory.h"
|
|
29 |
#include "mpsongscanner.h"
|
|
30 |
#include "mpmtpinfolink.h"
|
|
31 |
#include "mptrace.h"
|
|
32 |
|
|
33 |
/*!
|
|
34 |
\class MpGlobalPopupHandler
|
|
35 |
\brief Music Player global popup handler.
|
|
36 |
|
|
37 |
This class controls the asynchronous operation of all global dialogs.
|
|
38 |
*/
|
|
39 |
|
|
40 |
// Popups launched by this class
|
|
41 |
const QString KScanProgressDialog = QString( "ScanProgressDialog" );
|
|
42 |
const QString KDiskFullDialog = QString( "DiskFullDialog" );
|
|
43 |
const QString KScanFinished = QString( "ScanFinishedDialog" );
|
|
44 |
const QString KUnableToContinueDueUSB = QString( "UnableToContinueDueUSB" );
|
|
45 |
const QString KUsbBlockingNote = QString( "UsbBlockingNote" );
|
|
46 |
const QString KPromptRefresh = QString( "PromptRefresh" );
|
|
47 |
const QString KMTPInfoDialog = QString( "MTPInfoDialog" );
|
|
48 |
|
|
49 |
// Popups Actions
|
|
50 |
const QString KYes = QString( "yes" );
|
|
51 |
const QString KNo = QString( "no" );
|
|
52 |
|
|
53 |
/*!
|
|
54 |
Constructs the collection popup handler.
|
|
55 |
*/
|
|
56 |
MpGlobalPopupHandler::MpGlobalPopupHandler( QObject *parent )
|
|
57 |
: QObject( parent ),
|
|
58 |
mOutstandingPopup( 0 ),
|
|
59 |
mMpEngine( 0 ),
|
|
60 |
mMpSongScanner( 0 )
|
|
61 |
{
|
|
62 |
TX_ENTRY
|
|
63 |
mMpEngine = MpEngineFactory::sharedEngine();
|
|
64 |
connect( mMpEngine, SIGNAL( libraryAboutToUpdate() ), this, SLOT( handleLibraryAboutToUpdate() ) );
|
|
65 |
connect( mMpEngine, SIGNAL( unableToCotinueDueUSB() ), this, SLOT( launchUnableToCotinueDueUsb() ) );
|
|
66 |
connect( mMpEngine, SIGNAL( usbSynchronizationStarted() ), this, SLOT( launchUsbBlockingNote() ) );
|
|
67 |
connect( mMpEngine, SIGNAL( usbSynchronizationFinished() ), this, SLOT( closeUsbBlockingNote() ) );
|
|
68 |
TX_EXIT
|
|
69 |
}
|
|
70 |
|
|
71 |
/*!
|
|
72 |
Destructs the collection popup handler.
|
|
73 |
*/
|
|
74 |
MpGlobalPopupHandler::~MpGlobalPopupHandler()
|
|
75 |
{
|
|
76 |
TX_ENTRY
|
|
77 |
delete mOutstandingPopup;
|
|
78 |
TX_EXIT
|
|
79 |
}
|
|
80 |
|
|
81 |
/*!
|
|
82 |
Closes any active popup
|
|
83 |
*/
|
|
84 |
void MpGlobalPopupHandler::cancelOngoingPopup()
|
|
85 |
{
|
|
86 |
TX_ENTRY
|
|
87 |
if ( mOutstandingPopup ) {
|
|
88 |
mOutstandingPopup->close();
|
|
89 |
}
|
|
90 |
TX_EXIT
|
|
91 |
}
|
|
92 |
|
|
93 |
/*!
|
|
94 |
Slot called upon MpEngine signal libraryAboutToUpdate(). Used to connect with SongScanner.
|
|
95 |
*/
|
|
96 |
void MpGlobalPopupHandler::handleLibraryAboutToUpdate()
|
|
97 |
{
|
|
98 |
TX_ENTRY
|
|
99 |
if ( !mMpSongScanner && mMpEngine->songScanner() ) {
|
|
100 |
mMpSongScanner = mMpEngine->songScanner();
|
|
101 |
connect( mMpSongScanner, SIGNAL( scanStarted() ), this, SLOT( launchScanDialog() ) );
|
|
102 |
connect( mMpSongScanner, SIGNAL( scanCountChanged( int ) ), this, SLOT( scanCountChanged( int ) ) );
|
|
103 |
connect( mMpSongScanner, SIGNAL( scanFinished( int, int ) ),
|
|
104 |
this, SLOT( handleScanFinished( int, int ) ) );
|
|
105 |
}
|
|
106 |
TX_EXIT
|
|
107 |
}
|
|
108 |
|
|
109 |
/*!
|
|
110 |
Slot called upon notification from MpSongScanner indicating start of
|
|
111 |
scanning process.
|
|
112 |
*/
|
|
113 |
void MpGlobalPopupHandler::launchScanDialog()
|
|
114 |
{
|
|
115 |
TX_ENTRY
|
|
116 |
HbProgressDialog* scanProgressDialog = new HbProgressDialog( HbProgressDialog::WaitDialog );
|
|
117 |
connect( scanProgressDialog, SIGNAL( cancelled() ), mMpSongScanner, SLOT( cancelScan() ) );
|
|
118 |
scanProgressDialog->setModal( true );
|
43
|
119 |
HbLabel *title = new HbLabel( hbTrId( "txt_mus_info_refreshingnln_songs_added" ) );
|
37
|
120 |
title->setFontSpec(HbFontSpec(HbFontSpec::Primary));
|
|
121 |
|
|
122 |
scanProgressDialog->setHeadingWidget( title );
|
|
123 |
scanProgressDialog->setText( QString("") );
|
|
124 |
scanProgressDialog->setAttribute( Qt::WA_DeleteOnClose );
|
|
125 |
scanProgressDialog->setObjectName( KScanProgressDialog );
|
|
126 |
setOutstandingPopup( scanProgressDialog );
|
|
127 |
scanProgressDialog->show();
|
|
128 |
TX_EXIT
|
|
129 |
}
|
|
130 |
|
|
131 |
/*!
|
|
132 |
Slot called upon notification from MpSongScanner indicating the number of
|
|
133 |
songs scanned so far.
|
|
134 |
*/
|
|
135 |
void MpGlobalPopupHandler::scanCountChanged(int count)
|
|
136 |
{
|
|
137 |
TX_ENTRY_ARGS("count " << count )
|
|
138 |
if ( mOutstandingPopup && ( mOutstandingPopup->objectName() == KScanProgressDialog ) ) {
|
|
139 |
HbProgressDialog *dialog = qobject_cast<HbProgressDialog *>( mOutstandingPopup );
|
|
140 |
QString added;
|
43
|
141 |
added = hbTrId( "txt_mus_info_ln_songs_found" , count );
|
37
|
142 |
dialog->setText( added );
|
|
143 |
}
|
|
144 |
TX_EXIT
|
|
145 |
}
|
|
146 |
|
|
147 |
/*!
|
|
148 |
Slot called upon notification from MpSongScanner. Used to close current scan progress note,
|
|
149 |
and display scan results.
|
|
150 |
|
|
151 |
*/
|
|
152 |
void MpGlobalPopupHandler::handleScanFinished( int error, int itemsAdded )
|
|
153 |
{
|
|
154 |
TX_ENTRY_ARGS("error: " << error << " Items added: " << itemsAdded )
|
43
|
155 |
Q_UNUSED( itemsAdded );
|
37
|
156 |
if ( mOutstandingPopup && ( mOutstandingPopup->objectName() == KScanProgressDialog ) ) {
|
|
157 |
HbProgressDialog *dialog = qobject_cast<HbProgressDialog *>( mOutstandingPopup );
|
|
158 |
disconnect( dialog, SIGNAL( aboutToClose() ), this, SLOT( outstandingPopupClosing() ) );
|
|
159 |
mOutstandingPopup = 0;
|
|
160 |
dialog->close();
|
|
161 |
}
|
|
162 |
|
|
163 |
switch( error ) {
|
|
164 |
case MpSongScanner::ScanErrorNone :
|
43
|
165 |
launchScanFinishedDialog( true );
|
37
|
166 |
break;
|
|
167 |
case MpSongScanner::ScanGeneralError :
|
43
|
168 |
launchScanFinishedDialog( false );
|
37
|
169 |
break;
|
|
170 |
case MpSongScanner::ScanErrorDiskFull :
|
|
171 |
launchDiskFullDialog();
|
|
172 |
break;
|
|
173 |
case MpSongScanner::ScanInterrupted :
|
|
174 |
default:
|
|
175 |
//When scan interrupted (DiskEvent) just dimsiss the scanning progress note.
|
|
176 |
break;
|
|
177 |
}
|
|
178 |
TX_EXIT
|
|
179 |
}
|
|
180 |
|
|
181 |
/*!
|
|
182 |
Slot called when MpEngine emits unableToCotinueDueUSB() signal
|
|
183 |
*/
|
|
184 |
void MpGlobalPopupHandler::launchUnableToCotinueDueUsb()
|
|
185 |
{
|
|
186 |
HbMessageBox *dialog = new HbMessageBox( HbMessageBox::MessageTypeInformation );
|
|
187 |
dialog->setText( hbTrId( "txt_mus_info_usb_conn_in_progress" ) );
|
|
188 |
dialog->setModal( true );
|
|
189 |
dialog->setAttribute( Qt::WA_DeleteOnClose );
|
|
190 |
dialog->setObjectName( KUnableToContinueDueUSB );
|
|
191 |
setOutstandingPopup( dialog );
|
|
192 |
dialog->show();
|
|
193 |
}
|
|
194 |
|
|
195 |
/*!
|
|
196 |
Slot called when MpEngine emits usbSynchronizationStarted() signal
|
|
197 |
*/
|
|
198 |
void MpGlobalPopupHandler::launchUsbBlockingNote()
|
|
199 |
{
|
|
200 |
HbProgressDialog *usbBlockingNote = new HbProgressDialog( HbProgressDialog::WaitDialog );
|
|
201 |
usbBlockingNote->setModal( true );
|
|
202 |
if ( usbBlockingNote->actions().count() ) {
|
|
203 |
//Hide cancel action.
|
|
204 |
usbBlockingNote->actions().at( 0 )->setVisible( false );
|
|
205 |
}
|
|
206 |
usbBlockingNote->setDismissPolicy( HbPopup::NoDismiss );
|
|
207 |
usbBlockingNote->setText( hbTrId( "txt_mus_info_usb_conn_in_progress" ) );
|
|
208 |
usbBlockingNote->setAttribute( Qt::WA_DeleteOnClose );
|
|
209 |
usbBlockingNote->setObjectName( KUsbBlockingNote );
|
|
210 |
setOutstandingPopup( usbBlockingNote );
|
|
211 |
usbBlockingNote->show();
|
|
212 |
}
|
|
213 |
|
|
214 |
/*!
|
|
215 |
Slot called when MpEngine emits usbSynchronizationFinished() signal
|
|
216 |
*/
|
|
217 |
void MpGlobalPopupHandler::closeUsbBlockingNote()
|
|
218 |
{
|
|
219 |
if ( mOutstandingPopup && ( mOutstandingPopup->objectName() == KUsbBlockingNote ) ) {
|
|
220 |
HbProgressDialog *dialog = qobject_cast<HbProgressDialog *>( mOutstandingPopup );
|
|
221 |
dialog->cancel();
|
|
222 |
}
|
|
223 |
}
|
|
224 |
|
|
225 |
/*!
|
|
226 |
Slot to launch the MTP educating info dialog
|
43
|
227 |
This dialog would be displayed after any manual refresh (from options menu),
|
|
228 |
or after a refreshing originated by USBMassStorage disconnection.
|
37
|
229 |
*/
|
|
230 |
void MpGlobalPopupHandler::launchMTPInfoDialog()
|
|
231 |
{
|
|
232 |
TX_ENTRY
|
|
233 |
HbDialog *dialog = new HbDialog();
|
|
234 |
dialog->setContentWidget( new MpMtpInfoLink() );
|
|
235 |
dialog->setModal( true );
|
|
236 |
dialog->setDismissPolicy( HbPopup::NoDismiss);
|
|
237 |
dialog->setTimeout( HbPopup::NoTimeout );
|
|
238 |
HbAction *action;
|
|
239 |
action = new HbAction( hbTrId( "txt_common_button_yes" ) );
|
|
240 |
action->setObjectName( KYes );
|
|
241 |
dialog->addAction( action );
|
|
242 |
action = new HbAction( hbTrId( "txt_common_button_no" ) );
|
|
243 |
action->setObjectName( KNo );
|
|
244 |
dialog->addAction( action );
|
|
245 |
dialog->setAttribute( Qt::WA_DeleteOnClose );
|
|
246 |
dialog->setObjectName( KMTPInfoDialog );
|
|
247 |
setOutstandingPopup( dialog );
|
|
248 |
dialog->open( this, SLOT( hanldeMTPInfoDialogFinished( HbAction* ) ) );
|
|
249 |
TX_EXIT
|
|
250 |
}
|
|
251 |
|
|
252 |
/*!
|
|
253 |
Slot to be called when MtpInfoDialog has finished.
|
|
254 |
*/
|
|
255 |
void MpGlobalPopupHandler::hanldeMTPInfoDialogFinished( HbAction *selectedAction )
|
|
256 |
{
|
|
257 |
TX_ENTRY
|
|
258 |
if ( selectedAction && selectedAction->objectName() == KNo ) {
|
|
259 |
MpSettingsManager::instance()->stopShowingMtpInfo();
|
|
260 |
}
|
|
261 |
TX_EXIT
|
|
262 |
}
|
|
263 |
|
|
264 |
/*!
|
|
265 |
Slot to be called when a popup is getting closed. Usefull when a dialog is closed before it finishes
|
|
266 |
(dialog not closed by a direct user action).
|
|
267 |
*/
|
|
268 |
void MpGlobalPopupHandler::outstandingPopupClosing()
|
|
269 |
{
|
|
270 |
TX_ENTRY
|
|
271 |
HbPopup *popup = qobject_cast<HbPopup *>( sender() );
|
|
272 |
if ( popup ) {
|
|
273 |
Q_ASSERT( popup == mOutstandingPopup );
|
|
274 |
mOutstandingPopup = 0;
|
|
275 |
}
|
|
276 |
TX_EXIT
|
|
277 |
}
|
|
278 |
|
|
279 |
/*!
|
|
280 |
\internal
|
|
281 |
Launches Scan Finished Notification.
|
|
282 |
*/
|
43
|
283 |
void MpGlobalPopupHandler::launchScanFinishedDialog( bool ok )
|
37
|
284 |
{
|
|
285 |
HbNotificationDialog *finishedDialog = new HbNotificationDialog();
|
|
286 |
finishedDialog->setModal(true);
|
|
287 |
finishedDialog->setAttribute( Qt::WA_DeleteOnClose );
|
|
288 |
finishedDialog->setObjectName( KScanFinished );
|
|
289 |
// Connect aboutToClose with outstandingPopupClosing() first, and then with launchMTPInfoDialog
|
|
290 |
// in order to get finishDialog cleared before MtpInfoDialog is launched.
|
|
291 |
setOutstandingPopup( finishedDialog );
|
|
292 |
|
|
293 |
if( ok ) {
|
|
294 |
finishedDialog->setIcon( HbIcon( QString("qtg_large_ok") ) );
|
|
295 |
finishedDialog->setTitle( hbTrId( "txt_mus_dpophead_refresh_complete" ) );
|
|
296 |
if ( MpSettingsManager::showMtpInfo() && !mMpSongScanner->isAutomaticScan() ) {
|
|
297 |
connect( finishedDialog, SIGNAL( aboutToClose() ), this, SLOT( launchMTPInfoDialog() ) );
|
|
298 |
}
|
|
299 |
}
|
|
300 |
else {
|
|
301 |
finishedDialog->setIcon( HbIcon( QString("qtg_small_fail") ) );
|
|
302 |
finishedDialog->setTitle( hbTrId( "txt_mus_dpophead_refresh_cancelled" ) );
|
|
303 |
}
|
|
304 |
|
|
305 |
finishedDialog->show();
|
|
306 |
}
|
|
307 |
|
|
308 |
/*!
|
|
309 |
\internal
|
|
310 |
Launches DiskFull Notification
|
|
311 |
*/
|
|
312 |
void MpGlobalPopupHandler::launchDiskFullDialog()
|
|
313 |
{
|
|
314 |
TX_ENTRY
|
|
315 |
QString diskfull;
|
|
316 |
diskfull = hbTrId( "txt_mus_title_refresh_cancelled" );
|
|
317 |
diskfull.append(" ");
|
|
318 |
diskfull.append( hbTrId( "txt_mus_info_out_of_disk_space" ) );
|
|
319 |
HbMessageBox *diskFullDialog = new HbMessageBox();
|
|
320 |
diskFullDialog->setIcon( HbIcon( QString("qtg_small_fail") ) );
|
|
321 |
diskFullDialog->setText( diskfull );
|
|
322 |
diskFullDialog->setTimeout( HbPopup::NoTimeout);
|
|
323 |
diskFullDialog->setAttribute( Qt::WA_DeleteOnClose );
|
|
324 |
diskFullDialog->setObjectName( KDiskFullDialog );
|
|
325 |
setOutstandingPopup( diskFullDialog );
|
|
326 |
diskFullDialog->show();
|
|
327 |
TX_EXIT
|
|
328 |
}
|
|
329 |
|
|
330 |
/*!
|
|
331 |
\internal
|
|
332 |
sets \a popup as the current outstanding popup and cancels any other previous popup.
|
|
333 |
*/
|
|
334 |
void MpGlobalPopupHandler::setOutstandingPopup( HbPopup *popup )
|
|
335 |
{
|
|
336 |
TX_ENTRY
|
|
337 |
if ( mOutstandingPopup ) {
|
|
338 |
TX_LOG_ARGS( "Warning: Multiple popups attempted to be displayed" );
|
|
339 |
if ( mOutstandingPopup->objectName() == KScanFinished ) {
|
|
340 |
disconnect( mOutstandingPopup, SIGNAL( aboutToClose() ), this, SLOT( launchMTPInfoDialog() ) );
|
|
341 |
}
|
|
342 |
mOutstandingPopup->close();
|
|
343 |
}
|
|
344 |
|
|
345 |
connect( popup, SIGNAL( aboutToClose() ), this, SLOT( outstandingPopupClosing() ) );
|
|
346 |
mOutstandingPopup = popup;
|
|
347 |
TX_EXIT
|
|
348 |
}
|
|
349 |
|