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 song scanner. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <hbprogressdialog.h> |
|
19 #include <hbnotificationdialog.h> |
|
20 #include <hblabel.h> |
|
21 #include <hbfontspec.h> |
|
22 #include <hbmessagebox.h> |
|
23 |
|
24 #include "mpsongscanner.h" |
|
25 #include "mpmpxharvesterframeworkwrapper.h" |
|
26 #include "mptrace.h" |
|
27 |
|
28 /*! |
|
29 \class MpSongScanner |
|
30 \brief Music Player song scanner. |
|
31 |
|
32 Song scanner interfaces with MPX Harvesting Framework to harvest |
|
33 music files in the device. |
|
34 */ |
|
35 |
|
36 /*! |
|
37 \fn void scanEnd() |
|
38 |
|
39 This signal is emitted when scanning is ended. |
|
40 |
|
41 \sa scan() |
|
42 */ |
|
43 |
|
44 /*! |
|
45 Constructs the song scanner. |
|
46 */ |
|
47 MpSongScanner::MpSongScanner( MpMpxHarvesterFrameworkWrapper *wrapper, QObject *parent ) |
|
48 : QObject( parent ), |
|
49 mMpxWrapper(wrapper), |
|
50 mScanProgressNote(0), |
|
51 mScanning(false) |
|
52 { |
|
53 TX_ENTRY |
|
54 connect( mMpxWrapper, SIGNAL(scanStarted()), this, SLOT(handleScanStarted()) ); |
|
55 connect( mMpxWrapper, SIGNAL(scanEnded( int, int )), this, SLOT(handleScanEnded( int, int )) ); |
|
56 connect( mMpxWrapper, SIGNAL(scanCountChanged(int)), this, SLOT(handleScanCountChanged(int)) ); |
|
57 TX_EXIT |
|
58 } |
|
59 |
|
60 /*! |
|
61 Destructs the song scanner. |
|
62 */ |
|
63 MpSongScanner::~MpSongScanner() |
|
64 { |
|
65 TX_LOG |
|
66 } |
|
67 |
|
68 /*! |
|
69 Initiates song scanning. |
|
70 */ |
|
71 void MpSongScanner::scan() |
|
72 { |
|
73 if ( !mScanning ) { |
|
74 mScanning = true; |
|
75 mMpxWrapper->scan(); |
|
76 } |
|
77 } |
|
78 |
|
79 /*! |
|
80 Returns true if scanning is ongoing. |
|
81 */ |
|
82 bool MpSongScanner::isScanning() |
|
83 { |
|
84 return mScanning; |
|
85 } |
|
86 |
|
87 /*! |
|
88 Cancels ongoing song scanning, if any. |
|
89 |
|
90 \sa scan() |
|
91 */ |
|
92 void MpSongScanner::cancelScan() |
|
93 { |
|
94 if ( mScanning ) { |
|
95 mScanning = false; |
|
96 mMpxWrapper->cancelScan(); |
|
97 } |
|
98 } |
|
99 |
|
100 /*! |
|
101 Slot called upon notification from MPX Harvesting FW indicating start of |
|
102 scanning process. |
|
103 */ |
|
104 void MpSongScanner::handleScanStarted() |
|
105 { |
|
106 if ( !mScanProgressNote ) { |
|
107 mScanProgressNote = new HbProgressDialog( HbProgressDialog::WaitDialog ); |
|
108 connect( mScanProgressNote, SIGNAL( cancelled() ), this, SLOT( cancelScan() ) ); |
|
109 connect( mScanProgressNote, SIGNAL( aboutToClose() ), this, SLOT( handleProgressNoteClosing() ) ); |
|
110 } |
|
111 mScanProgressNote->setModal( true ); |
|
112 HbLabel *title = new HbLabel( hbTrId( "txt_mus_title_refreshing" ) ); |
|
113 title->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
|
114 |
|
115 mScanProgressNote->setHeadingWidget( title ); |
|
116 mScanProgressNote->setText( QString("") ); |
|
117 mScanProgressNote->setAttribute( Qt::WA_DeleteOnClose ); |
|
118 mScanProgressNote->show(); |
|
119 } |
|
120 |
|
121 /*! |
|
122 Slot called upon notification from MPX Harvesting FW indicating end of |
|
123 scanning process. |
|
124 */ |
|
125 void MpSongScanner::handleScanEnded( int numItemsAdded, int error ) |
|
126 { |
|
127 if (error == KErrDiskFull) { |
|
128 if ( mScanProgressNote ) { |
|
129 mScanProgressNote->cancel(); |
|
130 } |
|
131 HbMessageBox *diskFullDialog = new HbMessageBox(); |
|
132 diskFullDialog->setIcon( HbIcon( QString("qtg_small_fail") ) ); |
|
133 diskFullDialog->setText( hbTrId( "txt_mus_title_refresh_cancelled" ) ); |
|
134 diskFullDialog->setTimeout( HbPopup::NoTimeout); |
|
135 diskFullDialog->setAttribute( Qt::WA_DeleteOnClose ); |
|
136 diskFullDialog->show(); |
|
137 mScanning = false; |
|
138 |
|
139 } |
|
140 else{ |
|
141 QString added; |
|
142 HbNotificationDialog *finishedDialog = new HbNotificationDialog(); |
|
143 finishedDialog->setModal(true); |
|
144 finishedDialog->setAttribute( Qt::WA_DeleteOnClose ); |
|
145 |
|
146 added = hbTrId( "txt_mus_dpopinfo_ln_songs_added", numItemsAdded ); |
|
147 finishedDialog->setText( added ); |
|
148 |
|
149 if( error < 0) { |
|
150 if ( mScanProgressNote ) { |
|
151 mScanProgressNote->cancel(); |
|
152 } |
|
153 finishedDialog->setIcon( HbIcon( QString("qtg_small_fail") ) ); |
|
154 finishedDialog->setTitle( hbTrId( "txt_mus_dpophead_refresh_cancelled" ) ); |
|
155 } |
|
156 else if ( mScanning ) { |
|
157 if ( mScanProgressNote ) { |
|
158 mScanProgressNote->cancel(); |
|
159 } |
|
160 finishedDialog->setIcon( HbIcon( QString("qtg_large_ok") ) ); |
|
161 finishedDialog->setTitle( hbTrId( "txt_mus_dpophead_refresh_complete" ) ); |
|
162 } |
|
163 else { |
|
164 finishedDialog->setIcon( HbIcon( QString("qtg_small_fail") ) ); |
|
165 finishedDialog->setTitle( hbTrId( "txt_mus_dpophead_refresh_cancelled" ) ); |
|
166 } |
|
167 mScanning = false; |
|
168 finishedDialog->show(); |
|
169 } |
|
170 } |
|
171 |
|
172 /*! |
|
173 Slot called upon notification from MPX Harvesting FW indicating the number of |
|
174 songs scanned so far. |
|
175 */ |
|
176 void MpSongScanner::handleScanCountChanged(int count) |
|
177 { |
|
178 QString added; |
|
179 |
|
180 added = hbTrId( "txt_mus_info_ln_songs_added" , count ); |
|
181 if ( mScanProgressNote ) { |
|
182 mScanProgressNote->setText( added ); |
|
183 } |
|
184 } |
|
185 |
|
186 /*! |
|
187 Slot to be called when disk event is received from MPX framework. |
|
188 */ |
|
189 void MpSongScanner::handleDiskEvent( MpxDiskEvents event ) |
|
190 { |
|
191 Q_UNUSED( event ); |
|
192 if ( mScanning ) { |
|
193 if ( mScanProgressNote ) { |
|
194 mScanProgressNote->cancel(); |
|
195 } |
|
196 mScanning = false; |
|
197 // AK - Should we show a dialog? |
|
198 } |
|
199 TX_EXIT |
|
200 } |
|
201 |
|
202 /*! |
|
203 Slot used to clear mScanProgressNote when dialog is closing. |
|
204 */ |
|
205 void MpSongScanner::handleProgressNoteClosing() |
|
206 { |
|
207 mScanProgressNote = 0; |
|
208 } |
|
209 |
|