|
1 /* |
|
2 * Copyright (c) 2008-2008 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: Manages MCP plugins, and content publishing. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <LiwServiceHandler.h> |
|
20 #include <mpxcollectionmessagedefs.h> |
|
21 #include <mpxmessagecontainerdefs.h> |
|
22 #include <mpxmediacollectiondetaildefs.h> |
|
23 #include <mpxmessagegeneraldefs.h> |
|
24 #include <mpxcollectionutility.h> |
|
25 #include <mpxcollectionpath.h> |
|
26 #include <mpxcollectionhelperfactory.h> |
|
27 #include <mpxcollectionuihelper.h> |
|
28 #include <mpxcollectionmessage.h> |
|
29 |
|
30 #include "cpglobals.h" //This will be moved to domain API (HSFW) |
|
31 #include "mpxcollectionpublisher.h" |
|
32 |
|
33 |
|
34 |
|
35 _LIT8( KMCPDataKey,"musicmenu_collectioninfo_numb1data" ); |
|
36 _LIT( KMCPublisher, "MpxCollectionPublisher" ); |
|
37 _LIT( KMCPType,"integer" ); |
|
38 _LIT( KMCPContent,"musicmenu_collectioninfo_numb1" ); |
|
39 |
|
40 // ======== MEMBER FUNCTIONS ======== |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // Constructor |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CMpxCollectionPublisher::CMpxCollectionPublisher( |
|
47 MLiwInterface* aCPSInterface ) : iRefreshOperation( EFalse ) |
|
48 { |
|
49 iCPSInterface = aCPSInterface; |
|
50 |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Symbian 2nd phase constructor can leave. |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 void CMpxCollectionPublisher::ConstructL() |
|
58 { |
|
59 iDefaultAttrs.Append( KMPXMediaColDetailNumberOfItems ); |
|
60 iCollectionUiHelper = |
|
61 CMPXCollectionHelperFactory:: NewCollectionUiHelperL(); |
|
62 iCollectionUtility = |
|
63 MMPXCollectionUtility::NewL( this, KMcModeIsolated ); |
|
64 |
|
65 TUid collection = KLocalCollection; |
|
66 collection = iCollectionUtility-> |
|
67 Collection().CollectionIDL( collection ); |
|
68 iCollectionUtility->Collection().CommandL( EMcCmdCollectionInit, |
|
69 collection.iUid ); |
|
70 //music |
|
71 iAllSongsPath = iCollectionUiHelper->MusicAllSongsPathL(); |
|
72 iCollectionUtility->Collection().CancelRequest(); |
|
73 iCollectionUtility->Collection().MediaL( *iAllSongsPath , |
|
74 iDefaultAttrs.Array()); |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // Two-phased constructor. |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 CMpxCollectionPublisher* CMpxCollectionPublisher::NewL( |
|
82 MLiwInterface* aCPSInterface ) |
|
83 { |
|
84 CMpxCollectionPublisher* self = |
|
85 new ( ELeave ) CMpxCollectionPublisher( aCPSInterface ); |
|
86 CleanupStack::PushL( self ); |
|
87 self->ConstructL(); |
|
88 CleanupStack::Pop( self ); |
|
89 return self; |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // Destructor |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 CMpxCollectionPublisher::~CMpxCollectionPublisher() |
|
97 { |
|
98 if ( iCollectionUiHelper ) |
|
99 { |
|
100 iCollectionUiHelper->Close(); |
|
101 } |
|
102 |
|
103 if ( iCollectionUtility ) |
|
104 { |
|
105 iCollectionUtility->Close(); |
|
106 } |
|
107 iDefaultAttrs.Close(); |
|
108 delete iAllSongsPath; |
|
109 } |
|
110 |
|
111 |
|
112 void CMpxCollectionPublisher::UpdateL() |
|
113 { |
|
114 |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // From MMPXCollectionObserver |
|
119 // empty |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CMpxCollectionPublisher::HandleOpenL( const CMPXMedia& /* aMedia */, |
|
123 TInt /* aIndex */, |
|
124 TBool /* aComplete */,TInt /* aError */ ) |
|
125 { |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // From MMPXCollectionObserver |
|
130 // empty |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 void CMpxCollectionPublisher::HandleOpenL( |
|
134 const CMPXCollectionPlaylist& /* aPlaylist */, |
|
135 TInt /* aError */) |
|
136 { |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // From MMPXCollectionObserver |
|
141 // Handles MediaL |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 void CMpxCollectionPublisher::HandleCollectionMediaL( const CMPXMedia& aMedia, |
|
145 TInt aError ) |
|
146 { |
|
147 if (KErrNone == aError && |
|
148 aMedia.IsSupported( KMPXMediaColDetailNumberOfItems ) ) |
|
149 { |
|
150 TInt numberOfSongs = |
|
151 aMedia.ValueTObjectL<TBool>( KMPXMediaColDetailNumberOfItems ); |
|
152 PublishNumberL( numberOfSongs ); |
|
153 } |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // Handle collection messages. |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 void CMpxCollectionPublisher::HandleCollectionMessageL( CMPXMessage* aMsg ) |
|
161 { |
|
162 TMPXMessageId messageId = |
|
163 aMsg->ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ); |
|
164 if ( messageId == KMPXMessageGeneral ) |
|
165 { |
|
166 DoHandleGeneralMessageL( *aMsg ); |
|
167 } |
|
168 else if( messageId == KMPXMessageIdItemChanged ) |
|
169 { |
|
170 // Loop through messages for arrays. |
|
171 // |
|
172 if ( aMsg->IsSupported( KMPXMessageArrayContents ) ) |
|
173 { |
|
174 CMPXMessageArray* messageArray = |
|
175 aMsg->Value<CMPXMessageArray>( KMPXMessageArrayContents ); |
|
176 |
|
177 User::LeaveIfNull( messageArray ); |
|
178 for( TInt i=0; i<messageArray->Count(); ++i ) |
|
179 { |
|
180 HandleCollectionMessage( (*messageArray)[i], KErrNone); |
|
181 } |
|
182 } |
|
183 else // Single item |
|
184 { |
|
185 DoHandleItemChangedMessageL( *aMsg ) ; |
|
186 } |
|
187 } |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // From MMPXCollectionObserver |
|
192 // Handle collection messages. |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 void CMpxCollectionPublisher::HandleCollectionMessage( CMPXMessage* aMsg, |
|
196 TInt aError ) |
|
197 { |
|
198 if ( aError == KErrNone && aMsg ) |
|
199 { |
|
200 TRAP_IGNORE( HandleCollectionMessageL( aMsg ) ); |
|
201 } |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------------------------- |
|
205 // Handle item change message. |
|
206 // --------------------------------------------------------------------------- |
|
207 // |
|
208 void CMpxCollectionPublisher::DoHandleItemChangedMessageL( |
|
209 const CMPXMessage& aMsg ) |
|
210 { |
|
211 TMPXChangeEventType eventType( |
|
212 aMsg.ValueTObjectL<TMPXChangeEventType>( |
|
213 KMPXMessageChangeEventType ) ); |
|
214 TMPXItemId itemId( |
|
215 aMsg.ValueTObjectL<TMPXItemId>(KMPXMessageMediaGeneralId ) ); |
|
216 |
|
217 if ( !iRefreshOperation && |
|
218 ( eventType == EMPXItemDeleted || eventType == EMPXItemInserted ) ) |
|
219 { |
|
220 //everytime an item is changed we need to refresh data |
|
221 iCollectionUtility->Collection().CancelRequest(); |
|
222 iCollectionUtility->Collection().MediaL( *iAllSongsPath , |
|
223 iDefaultAttrs.Array() ); |
|
224 } |
|
225 |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // Handle collection general message. |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 void CMpxCollectionPublisher::DoHandleGeneralMessageL( |
|
233 const CMPXMessage& aMsg ) |
|
234 { |
|
235 TInt event = aMsg.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ); |
|
236 TInt type = aMsg.ValueTObjectL<TInt>( KMPXMessageGeneralType ); |
|
237 |
|
238 |
|
239 if ( event == TMPXCollectionMessage::EBroadcastEvent && |
|
240 ( type == EMcMsgRefreshStart || type == EMcMsgFormatStart || |
|
241 type == EMcMsgUSBMassStorageStart || type == EMcMsgUSBMTPStart ) |
|
242 ) |
|
243 { |
|
244 //if refresh operation starts we block until refresh ends |
|
245 iRefreshOperation = ETrue; |
|
246 iCollectionUtility->Collection().CancelRequest(); |
|
247 } |
|
248 else if ( event == TMPXCollectionMessage::EBroadcastEvent && |
|
249 ( type == EMcMsgRefreshEnd || type == EMcMsgFormatEnd || |
|
250 type == EMcMsgDiskRemoved || type == EMcMsgDiskInserted || |
|
251 type == EMcMsgUSBMassStorageEnd || type == EMcMsgUSBMTPEnd ) |
|
252 ) |
|
253 { |
|
254 iRefreshOperation = EFalse; |
|
255 iCollectionUtility->Collection().CancelRequest(); |
|
256 iCollectionUtility->Collection().MediaL( *iAllSongsPath , |
|
257 iDefaultAttrs.Array() ); |
|
258 } |
|
259 } |
|
260 |
|
261 // --------------------------------------------------------------------------- |
|
262 // Publishes a number to the required destination |
|
263 // --------------------------------------------------------------------------- |
|
264 // |
|
265 |
|
266 void CMpxCollectionPublisher::PublishNumberL( const TInt aNumb ) |
|
267 { |
|
268 if ( iCPSInterface ) |
|
269 { |
|
270 CLiwGenericParamList * inParam = CLiwGenericParamList::NewLC(); |
|
271 CLiwGenericParamList * outParam = CLiwGenericParamList::NewLC(); |
|
272 |
|
273 TLiwGenericParam cptype( KType, TLiwVariant( KCpData ) ); |
|
274 inParam->AppendL( cptype ); |
|
275 CLiwDefaultMap * cpdatamap = CLiwDefaultMap::NewLC(); |
|
276 CLiwDefaultMap * map = CLiwDefaultMap::NewLC(); |
|
277 |
|
278 map->InsertL( KMCPDataKey, TLiwVariant( TInt32( aNumb ) ) ); |
|
279 |
|
280 cpdatamap->InsertL( KPublisherId, TLiwVariant( KMCPublisher ) ); |
|
281 cpdatamap->InsertL( KContentType, TLiwVariant( KMCPType ) ); |
|
282 cpdatamap->InsertL( KContentId, TLiwVariant( KMCPContent ) ); |
|
283 cpdatamap->InsertL( KDataMap, TLiwVariant( map ) ); |
|
284 |
|
285 TLiwGenericParam item( KItem, TLiwVariant( cpdatamap ) ); |
|
286 inParam->AppendL( item ); |
|
287 |
|
288 iCPSInterface->ExecuteCmdL( KAdd, *inParam, *outParam ); |
|
289 |
|
290 CleanupStack::PopAndDestroy( map ); |
|
291 CleanupStack::PopAndDestroy( cpdatamap ); |
|
292 CleanupStack::PopAndDestroy( outParam ); |
|
293 CleanupStack::PopAndDestroy( inParam ); |
|
294 } |
|
295 } |
|
296 |
|
297 |
|
298 // End of File |
|
299 |