|
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 Progress Dialogs Hanlder. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <hbprogressdialog.h> |
|
19 #include <hblabel.h> |
|
20 #include <hbfontspec.h> |
|
21 #include <hbnotificationdialog.h> |
|
22 #include <hbmessagebox.h> |
|
23 |
|
24 #include "mpprogressdialoghandler.h" |
|
25 #include "mpmpxcollectionframeworkwrapper.h" |
|
26 #include "mpmpxharvesterframeworkwrapper.h" |
|
27 #include "mptrace.h" |
|
28 |
|
29 /*! |
|
30 \class MpProgressDialogHandler |
|
31 \brief Music Player Progress Dialogs Handler. |
|
32 |
|
33 This class controls the asynchronous operation of all progress |
|
34 dialogs used by Music Player |
|
35 */ |
|
36 |
|
37 /*! |
|
38 Constructs the dialog handler. |
|
39 */ |
|
40 MpProgressDialogHandler::MpProgressDialogHandler( MpMpxCollectionFrameworkWrapper *cwrapper, MpMpxHarvesterFrameworkWrapper *hwrapper, QObject *parent ) |
|
41 : QObject( parent ), |
|
42 mMpxCollectionWrapper(cwrapper), |
|
43 mMpxHarvesterWrapper(hwrapper), |
|
44 mOutStandingProgressNote(0), |
|
45 mDeleting(false), |
|
46 mScanning(false) |
|
47 { |
|
48 TX_ENTRY |
|
49 connect( mMpxCollectionWrapper, SIGNAL(deleteStarted( TCollectionContext, TInt )), this, SLOT(handleDeleteStarted( TCollectionContext, TInt )) ); |
|
50 connect( mMpxCollectionWrapper, SIGNAL(songsDeleted( bool )), this, SLOT(handleDeleteEnded( bool )) ); |
|
51 connect( mMpxCollectionWrapper, SIGNAL( openAddSongsWaitDialog() ), this, SLOT(handleAddSongs() )); |
|
52 connect( mMpxCollectionWrapper, SIGNAL( playlistSaved( bool ) ), this, SLOT(handleAddSongsFinished( bool ) )); |
|
53 connect( mMpxHarvesterWrapper, SIGNAL(scanStarted()), this, SLOT(handleScanStarted()) ); |
|
54 connect( mMpxHarvesterWrapper, SIGNAL(scanEnded( int, int )), this, SLOT(handleScanEnded( int, int )) ); |
|
55 connect( mMpxHarvesterWrapper, SIGNAL(scanCountChanged(int)), this, SLOT(handleScanCountChanged(int)) ); |
|
56 TX_EXIT |
|
57 } |
|
58 |
|
59 /*! |
|
60 Destructs the dialog handler. |
|
61 */ |
|
62 MpProgressDialogHandler::~MpProgressDialogHandler() |
|
63 { |
|
64 TX_LOG |
|
65 } |
|
66 |
|
67 /*! |
|
68 Initiates song scanning. |
|
69 */ |
|
70 void MpProgressDialogHandler::scan() |
|
71 { |
|
72 if ( !mScanning ) { |
|
73 mScanning = true; |
|
74 mMpxHarvesterWrapper->scan(); |
|
75 } |
|
76 } |
|
77 |
|
78 /*! |
|
79 Returns true if scanning is ongoing. |
|
80 */ |
|
81 bool MpProgressDialogHandler::isScanning() |
|
82 { |
|
83 return mScanning; |
|
84 } |
|
85 |
|
86 /*! |
|
87 Initiates song deleting. |
|
88 */ |
|
89 void MpProgressDialogHandler::deleteSongs( QList<int> &selection ) |
|
90 { |
|
91 TX_ENTRY |
|
92 if ( !mDeleting ) { |
|
93 mDeleting = true; |
|
94 mMpxCollectionWrapper->deleteSongs( selection ); |
|
95 } |
|
96 TX_EXIT |
|
97 } |
|
98 |
|
99 /*! |
|
100 Slot called upon cancels ongoing request, if any. |
|
101 */ |
|
102 void MpProgressDialogHandler::cancelRequest() |
|
103 { |
|
104 TX_ENTRY |
|
105 mMpxCollectionWrapper->cancelRequest(); |
|
106 TX_EXIT |
|
107 } |
|
108 |
|
109 /*! |
|
110 Slot called upon notification from MPX FW Wrapper indicating start of |
|
111 deleting process. |
|
112 */ |
|
113 void MpProgressDialogHandler::handleDeleteStarted(TCollectionContext context, TInt count) |
|
114 { |
|
115 TX_ENTRY |
|
116 emit deleteStarted(); |
|
117 HbProgressDialog *deleteProgressNote = new HbProgressDialog( HbProgressDialog::WaitDialog ); |
|
118 connect( deleteProgressNote, SIGNAL( cancelled() ), this, SLOT( cancelRequest() ) ); |
|
119 connect( deleteProgressNote, SIGNAL( aboutToClose() ), this, SLOT( outstandingPopupClosing() ) ); |
|
120 deleteProgressNote->setModal( true ); |
|
121 deleteProgressNote->setDismissPolicy( HbPopup::NoDismiss ); |
|
122 if ( context == ECollectionContextPlaylistSongs ){ |
|
123 if (count >= 100) { //show progress dialog if removing more than 100 songs |
|
124 deleteProgressNote->setText( hbTrId( "txt_mus_info_removing_songs" ) ); |
|
125 setOutstandingPopup(deleteProgressNote); |
|
126 deleteProgressNote->show(); |
|
127 } |
|
128 } |
|
129 else if (context != ECollectionContextPlaylists ){ //no progress dialog for delete playlist |
|
130 deleteProgressNote->setText( hbTrId( "txt_mus_info_deleting" ) ); |
|
131 setOutstandingPopup(deleteProgressNote); |
|
132 deleteProgressNote->show(); |
|
133 } |
|
134 TX_EXIT |
|
135 } |
|
136 |
|
137 /*! |
|
138 Slot called upon notification from MPX FW CollectionHelper indicating end of |
|
139 deleting process. |
|
140 */ |
|
141 void MpProgressDialogHandler::handleDeleteEnded( bool success ) |
|
142 { |
|
143 TX_ENTRY |
|
144 Q_UNUSED( success ); |
|
145 HbProgressDialog *deleteProgressNote = qobject_cast<HbProgressDialog *>( mOutStandingProgressNote ); |
|
146 emit songsDeleted( success ); |
|
147 if ( deleteProgressNote ) { |
|
148 deleteProgressNote->cancel(); |
|
149 } |
|
150 mDeleting = false; |
|
151 TX_EXIT |
|
152 } |
|
153 |
|
154 /*! |
|
155 Slot called upon notification from MPX FW Wrapper indicating start of |
|
156 add songs process. |
|
157 */ |
|
158 void MpProgressDialogHandler::handleAddSongs() |
|
159 { |
|
160 HbProgressDialog *addSongsWaitNote = new HbProgressDialog( HbProgressDialog::WaitDialog ); |
|
161 connect( addSongsWaitNote, SIGNAL( cancelled() ), this, SLOT( cancelRequest() ) ); |
|
162 connect( addSongsWaitNote, SIGNAL( aboutToClose() ), this, SLOT( outstandingPopupClosing() ) ); |
|
163 addSongsWaitNote->setModal( true ); |
|
164 addSongsWaitNote->setText( hbTrId( "txt_mus_info_adding_songs" ) ); |
|
165 setOutstandingPopup( addSongsWaitNote ); |
|
166 addSongsWaitNote->show(); |
|
167 |
|
168 |
|
169 } |
|
170 |
|
171 /*! |
|
172 Slot called upon notification from MPX FW CollectionHelper indicating end of |
|
173 add songs process. |
|
174 */ |
|
175 void MpProgressDialogHandler::handleAddSongsFinished( bool success ) |
|
176 { |
|
177 Q_UNUSED(success); |
|
178 HbProgressDialog *addSongsWaitNote = qobject_cast<HbProgressDialog *>( mOutStandingProgressNote ); |
|
179 if (addSongsWaitNote){ |
|
180 addSongsWaitNote->cancel(); |
|
181 } |
|
182 } |
|
183 |
|
184 /*! |
|
185 Cancels ongoing song scanning, if any. |
|
186 |
|
187 \sa scan() |
|
188 */ |
|
189 void MpProgressDialogHandler::cancelScan() |
|
190 { |
|
191 if ( mScanning ) { |
|
192 mScanning = false; |
|
193 mMpxHarvesterWrapper->cancelScan(); |
|
194 } |
|
195 } |
|
196 |
|
197 /*! |
|
198 Slot called upon notification from MPX Harvesting FW indicating start of |
|
199 scanning process. |
|
200 */ |
|
201 void MpProgressDialogHandler::handleScanStarted() |
|
202 { |
|
203 HbProgressDialog *scanProgressNote = new HbProgressDialog( HbProgressDialog::WaitDialog ); |
|
204 connect( scanProgressNote, SIGNAL( cancelled() ), this, SLOT( cancelScan() ) ); |
|
205 connect( scanProgressNote, SIGNAL( aboutToClose() ), this, SLOT( outstandingPopupClosing() ) ); |
|
206 |
|
207 scanProgressNote->setModal( true ); |
|
208 HbLabel *title = new HbLabel( hbTrId( "txt_mus_title_refreshing" ) ); |
|
209 title->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
|
210 |
|
211 scanProgressNote->setHeadingWidget( title ); |
|
212 scanProgressNote->setText( QString("") ); |
|
213 setOutstandingPopup( scanProgressNote ); |
|
214 scanProgressNote->show(); |
|
215 } |
|
216 |
|
217 /*! |
|
218 Slot called upon notification from MPX Harvesting FW indicating end of |
|
219 scanning process. |
|
220 */ |
|
221 void MpProgressDialogHandler::handleScanEnded( int numItemsAdded, int error ) |
|
222 { |
|
223 HbProgressDialog *scanProgressNote = qobject_cast<HbProgressDialog *>( mOutStandingProgressNote ); |
|
224 if (error == KErrDiskFull) { |
|
225 if ( scanProgressNote ) { |
|
226 scanProgressNote->cancel(); |
|
227 } |
|
228 QString diskfull; |
|
229 diskfull = hbTrId( "txt_mus_title_refresh_cancelled" ); |
|
230 diskfull.append(" "); |
|
231 diskfull.append( hbTrId( "txt_mus_info_out_of_disk_space" ) ); |
|
232 HbMessageBox *diskFullDialog = new HbMessageBox(); |
|
233 setOutstandingPopup( diskFullDialog ); |
|
234 diskFullDialog->setIcon( HbIcon( QString("qtg_small_fail") ) ); |
|
235 diskFullDialog->setText( diskfull ); |
|
236 diskFullDialog->setTimeout( HbPopup::NoTimeout); |
|
237 diskFullDialog->show(); |
|
238 mScanning = false; |
|
239 |
|
240 } |
|
241 else{ |
|
242 QString added; |
|
243 HbNotificationDialog *finishedDialog = new HbNotificationDialog(); |
|
244 finishedDialog->setModal(true); |
|
245 |
|
246 added = hbTrId( "txt_mus_dpopinfo_ln_songs_added", numItemsAdded ); |
|
247 finishedDialog->setText( added ); |
|
248 |
|
249 if( error < 0) { |
|
250 if ( scanProgressNote ) { |
|
251 scanProgressNote->cancel(); |
|
252 } |
|
253 finishedDialog->setIcon( HbIcon( QString("qtg_small_fail") ) ); |
|
254 finishedDialog->setTitle( hbTrId( "txt_mus_dpophead_refresh_cancelled" ) ); |
|
255 } |
|
256 else if ( mScanning ) { |
|
257 if ( scanProgressNote ) { |
|
258 scanProgressNote->cancel(); |
|
259 } |
|
260 finishedDialog->setIcon( HbIcon( QString("qtg_large_ok") ) ); |
|
261 finishedDialog->setTitle( hbTrId( "txt_mus_dpophead_refresh_complete" ) ); |
|
262 } |
|
263 else { |
|
264 finishedDialog->setIcon( HbIcon( QString("qtg_small_fail") ) ); |
|
265 finishedDialog->setTitle( hbTrId( "txt_mus_dpophead_refresh_cancelled" ) ); |
|
266 } |
|
267 mScanning = false; |
|
268 setOutstandingPopup( finishedDialog ); |
|
269 finishedDialog->show(); |
|
270 } |
|
271 } |
|
272 |
|
273 /*! |
|
274 Slot called upon notification from MPX Harvesting FW indicating the number of |
|
275 songs scanned so far. |
|
276 */ |
|
277 void MpProgressDialogHandler::handleScanCountChanged(int count) |
|
278 { |
|
279 HbProgressDialog *scanProgressNote = qobject_cast<HbProgressDialog *>( mOutStandingProgressNote ); |
|
280 QString added; |
|
281 added = hbTrId( "txt_mus_info_ln_songs_added" , count ); |
|
282 if ( scanProgressNote ) { |
|
283 scanProgressNote->setText( added ); |
|
284 } |
|
285 } |
|
286 |
|
287 /*! |
|
288 Slot to be called when disk event is received from MPX framework. |
|
289 */ |
|
290 void MpProgressDialogHandler::handleDiskEvent( MpxDiskEvents event ) |
|
291 { |
|
292 Q_UNUSED( event ); |
|
293 HbProgressDialog *progressNote = qobject_cast<HbProgressDialog *>( mOutStandingProgressNote ); |
|
294 if ( progressNote ) { |
|
295 progressNote->cancel(); |
|
296 } |
|
297 mScanning = false; |
|
298 mDeleting = false; |
|
299 TX_EXIT |
|
300 } |
|
301 |
|
302 /*! |
|
303 Slot to be called when mOutStandingProgressNote is about to close. |
|
304 */ |
|
305 void MpProgressDialogHandler::handleOutstandingPopupClosing() |
|
306 { |
|
307 TX_ENTRY |
|
308 mOutStandingProgressNote = 0; |
|
309 TX_EXIT |
|
310 } |
|
311 |
|
312 /*! |
|
313 \internal |
|
314 sets \a popup as the current outstanding popup and cancels any other active popup. |
|
315 */ |
|
316 void MpProgressDialogHandler::setOutstandingPopup( HbPopup *popup ) |
|
317 { |
|
318 TX_ENTRY |
|
319 //Close previous popup |
|
320 if ( mOutStandingProgressNote ) { |
|
321 disconnect( mOutStandingProgressNote, SIGNAL( aboutToClose() ), this, SLOT( handleOutstandingPopupClosing() ) ); |
|
322 mOutStandingProgressNote->close(); |
|
323 } |
|
324 |
|
325 //Set new outstanding popup |
|
326 popup->setAttribute( Qt::WA_DeleteOnClose ); |
|
327 connect( popup, SIGNAL( aboutToClose() ), this, SLOT( handleOutstandingPopupClosing() ) ); |
|
328 mOutStandingProgressNote = popup; |
|
329 TX_EXIT |
|
330 } |
|
331 |