|
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 "mpsongscanner.h" |
|
19 #include "mpmpxharvesterframeworkwrapper.h" |
|
20 #include "mptrace.h" |
|
21 |
|
22 /*! |
|
23 \class MpSongScanner |
|
24 \brief Music Player song scanner. |
|
25 |
|
26 Song scanner interfaces with MPX Harvesting Framework to harvest |
|
27 music files in the device. |
|
28 */ |
|
29 |
|
30 /*! |
|
31 \fn void scanStarted() |
|
32 |
|
33 This signal is emitted when scanning has started. |
|
34 |
|
35 */ |
|
36 |
|
37 /*! |
|
38 \fn void scanCountChanged( int count ) |
|
39 |
|
40 This signal is emitted to notify that scan count has changed. |
|
41 |
|
42 */ |
|
43 |
|
44 /*! |
|
45 \fn void scanFinished( int error, int itemsAdded ) |
|
46 |
|
47 Emitted when scanning has finished. |
|
48 |
|
49 */ |
|
50 |
|
51 /*! |
|
52 Constructs the song scanner. |
|
53 */ |
|
54 MpSongScanner::MpSongScanner( MpMpxHarvesterFrameworkWrapper *wrapper, QObject *parent ) |
|
55 : QObject( parent ), |
|
56 mMpxHarvesterWrapper(wrapper), |
|
57 mScanning( false ), |
|
58 mAutomaticScan( true ) |
|
59 { |
|
60 TX_ENTRY |
|
61 connect( mMpxHarvesterWrapper, SIGNAL( scanStarted() ), |
|
62 this, SIGNAL( scanStarted() ), Qt::QueuedConnection ); |
|
63 connect( mMpxHarvesterWrapper, SIGNAL( scanEnded( int, int ) ), |
|
64 this, SLOT( handleScanEnded( int, int ) ), Qt::QueuedConnection ); |
|
65 connect( mMpxHarvesterWrapper, SIGNAL( scanCountChanged( int ) ), |
|
66 this, SIGNAL( scanCountChanged( int ) ), Qt::QueuedConnection ); |
|
67 connect( mMpxHarvesterWrapper, SIGNAL( diskEvent( MpxDiskEvents ) ), |
|
68 this, SLOT( handleDiskEvent(MpxDiskEvents) ), Qt::QueuedConnection ); |
|
69 TX_EXIT |
|
70 } |
|
71 |
|
72 /*! |
|
73 Destructs the song scanner. |
|
74 */ |
|
75 MpSongScanner::~MpSongScanner() |
|
76 { |
|
77 TX_LOG |
|
78 } |
|
79 |
|
80 /*! |
|
81 Initiates song scanning. |
|
82 */ |
|
83 void MpSongScanner::scan( bool automaticScan ) |
|
84 { |
|
85 TX_ENTRY |
|
86 if ( !mScanning ) { |
|
87 mScanning = true; |
|
88 mAutomaticScan = automaticScan; |
|
89 mMpxHarvesterWrapper->scan(); |
|
90 } |
|
91 TX_EXIT |
|
92 } |
|
93 |
|
94 /*! |
|
95 Returns mAutomaticScan value. |
|
96 */ |
|
97 bool MpSongScanner::isAutomaticScan() |
|
98 { |
|
99 return mAutomaticScan; |
|
100 } |
|
101 |
|
102 /*! |
|
103 Cancels ongoing song scanning, if any. |
|
104 |
|
105 \sa scan() |
|
106 */ |
|
107 void MpSongScanner::cancelScan() |
|
108 { |
|
109 TX_ENTRY |
|
110 if ( mScanning ) { |
|
111 mScanning = false; |
|
112 mMpxHarvesterWrapper->cancelScan(); |
|
113 } |
|
114 TX_EXIT |
|
115 } |
|
116 |
|
117 /*! |
|
118 Slot called upon notification from MPX Harvesting FW indicating end of |
|
119 scanning process. |
|
120 */ |
|
121 void MpSongScanner::handleScanEnded( int numItemsAdded, int error ) |
|
122 { |
|
123 TX_ENTRY |
|
124 if (error == KErrDiskFull) { |
|
125 emit scanFinished( ScanErrorDiskFull, 0 ); |
|
126 mScanning = false; |
|
127 } |
|
128 else{ |
|
129 if( error < 0) { |
|
130 emit scanFinished( ScanGeneralError, numItemsAdded ); |
|
131 } |
|
132 else if ( mScanning ) { |
|
133 emit scanFinished( ScanErrorNone, numItemsAdded ); |
|
134 } |
|
135 else { |
|
136 // Scan canceled |
|
137 emit scanFinished( ScanGeneralError, numItemsAdded ); |
|
138 } |
|
139 mScanning = false; |
|
140 } |
|
141 TX_EXIT |
|
142 } |
|
143 |
|
144 /*! |
|
145 Slot to be called when disk event is received from MPX framework. |
|
146 */ |
|
147 void MpSongScanner::handleDiskEvent( MpxDiskEvents event ) |
|
148 { |
|
149 TX_ENTRY |
|
150 Q_UNUSED( event ); |
|
151 if ( mScanning ) { |
|
152 emit scanFinished( ScanInterrupted, 0 ); |
|
153 mScanning = false; |
|
154 } |
|
155 TX_EXIT |
|
156 } |
|
157 |