|
1 /* |
|
2 * Copyright (c) 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: CMSSettingItemList class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <msgspluginsrc.rsg> |
|
20 #include <commdb.h> // for RProperty |
|
21 #include <StringLoader.h> // for StringLoader |
|
22 #include <centralrepository.h> // for profile |
|
23 #include <ProfileEngineSDKCRKeys.h> // for profile |
|
24 #include <driveinfo.h> |
|
25 |
|
26 #include "cmsettingsfactory.h" |
|
27 #include "cmcommonutils.h" |
|
28 #include "cmsettings.h" |
|
29 #include "cmdriveinfo.h" |
|
30 #include "mserv.hlp.hrh" |
|
31 #include "msengine.h" |
|
32 #include "mssettingitemlist.h" |
|
33 #include "mssettingitemmemory.h" // mmc name |
|
34 #include "mssettingitemdevices.h" // source devices |
|
35 #include "mssettingsview.h" |
|
36 #include "msconstants.h" |
|
37 #include "cmmediaserverfull.h" |
|
38 #include "msdebug.h" |
|
39 |
|
40 // CONSTANTS |
|
41 const TInt KOfflineProfile = 5; |
|
42 |
|
43 // ================= MEMBER FUNCTIONS ======================= |
|
44 |
|
45 // -------------------------------------------------------------------------- |
|
46 // CMSSettingItemList::NewL() |
|
47 // Two phase constructor. |
|
48 // -------------------------------------------------------------------------- |
|
49 // |
|
50 CMSSettingItemList* CMSSettingItemList::NewL( TInt aResourceId, |
|
51 CMSSettingsView& aView ) |
|
52 { |
|
53 LOG(_L("[MediaServant]\t CMSSettingItemList::NewL")); |
|
54 |
|
55 CMSSettingItemList* self = CMSSettingItemList::NewLC( aResourceId, |
|
56 aView ); |
|
57 |
|
58 CleanupStack::Pop( self ); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // -------------------------------------------------------------------------- |
|
63 // CMSSettingItemList::NewLC() |
|
64 // Two phase constructor. |
|
65 // -------------------------------------------------------------------------- |
|
66 // |
|
67 CMSSettingItemList* CMSSettingItemList::NewLC( TInt aResourceId, |
|
68 CMSSettingsView& aView ) |
|
69 { |
|
70 LOG(_L("[MediaServant]\t CMSSettingItemList::NewLC")); |
|
71 |
|
72 CMSSettingItemList* self = new ( ELeave ) CMSSettingItemList( |
|
73 aView ); |
|
74 CleanupStack::PushL( self ); |
|
75 self->ConstructL( aResourceId ); |
|
76 return self; |
|
77 } |
|
78 |
|
79 // -------------------------------------------------------------------------- |
|
80 // CMSSettingItemList::CMSSettingItemList() |
|
81 // -------------------------------------------------------------------------- |
|
82 // |
|
83 CMSSettingItemList::CMSSettingItemList( CMSSettingsView& aView ) |
|
84 : iView( aView ) |
|
85 { |
|
86 LOG(_L("[MediaServant]\t CMSSettingItemList::CMSSettingItemList")); |
|
87 } |
|
88 |
|
89 // -------------------------------------------------------------------------- |
|
90 // CMSSettingItemList::~CMSSettingItemList() |
|
91 // -------------------------------------------------------------------------- |
|
92 // |
|
93 CMSSettingItemList::~CMSSettingItemList() |
|
94 { |
|
95 LOG(_L("[MediaServant]\t CMSSettingItemList::~CMSSettingItemList")); |
|
96 |
|
97 if ( iStoredServers ) |
|
98 { |
|
99 iStoredServers->ResetAndDestroy(); |
|
100 iStoredServers->Close(); |
|
101 delete iStoredServers; |
|
102 } |
|
103 |
|
104 if ( iMSEngine ) |
|
105 { |
|
106 delete iMSEngine; |
|
107 } |
|
108 } |
|
109 |
|
110 // -------------------------------------------------------------------------- |
|
111 // CMSSettingItemList::ConstructL() |
|
112 // Second phase constructor. |
|
113 // -------------------------------------------------------------------------- |
|
114 // |
|
115 void CMSSettingItemList::ConstructL( TInt aResourceId ) |
|
116 { |
|
117 LOG(_L("[MediaServant]\t CMSSettingItemList::ConstructL")); |
|
118 |
|
119 // Create engine |
|
120 iMSEngine = CMSEngine::NewL(); |
|
121 |
|
122 // Set engine observer |
|
123 iMSEngine->SetObserver( this ); |
|
124 // Read memory manager setting |
|
125 iMemoryManager = |
|
126 iMSEngine->ServiceState( ECmServiceMemoryManager ); |
|
127 |
|
128 iSync = iMSEngine->ServiceState( ECmServiceContentManager ); |
|
129 |
|
130 // Get server list |
|
131 iStoredServers = iMSEngine->GetMediaServersL(); |
|
132 |
|
133 CAknSettingItemList::ConstructFromResourceL( aResourceId ); |
|
134 |
|
135 // sets memory selection setting visibility |
|
136 SetMemorySelectionL(); |
|
137 |
|
138 iListBox = ListBox(); |
|
139 } |
|
140 |
|
141 // -------------------------------------------------------------------------- |
|
142 // CMSSettingItemList::OpenSelectedListboxItemL |
|
143 // -------------------------------------------------------------------------- |
|
144 // |
|
145 void CMSSettingItemList::OpenSelectedListboxItemL() |
|
146 { |
|
147 LOG(_L("[MediaServant]\t CMSSettingItemList::OpenSelectedListboxItemL")); |
|
148 |
|
149 HandleListBoxEventL( ListBox(), EEventEnterKeyPressed ); |
|
150 } |
|
151 |
|
152 |
|
153 // -------------------------------------------------------------------------- |
|
154 // CMSSettingItemList::HandleListBoxEventL() |
|
155 // -------------------------------------------------------------------------- |
|
156 // |
|
157 void CMSSettingItemList::HandleListBoxEventL( CEikListBox *aListBox, |
|
158 TListBoxEvent aEventType) |
|
159 { |
|
160 LOG(_L("[MediaServant]\t CMSSettingItemList::HandleListBoxEventL")); |
|
161 |
|
162 CAknSettingItemList::HandleListBoxEventL( aListBox, aEventType ); |
|
163 |
|
164 // UI selection is stored to actual settings variable |
|
165 StoreSettingsL(); |
|
166 |
|
167 TInt listBoxItemIndex = iListBox->CurrentItemIndex(); |
|
168 CAknSettingItemArray* itemArray = SettingItemArray(); |
|
169 TInt realIndex = itemArray->ItemIndexFromVisibleIndex( |
|
170 listBoxItemIndex ); |
|
171 |
|
172 if ( realIndex == EMSSettingsSync ) |
|
173 { |
|
174 iMSEngine->SetServiceState( ECmServiceContentManager, |
|
175 iSync ); |
|
176 // inform plugin about changed setting |
|
177 TCmProgressInfo info; |
|
178 info.iProcessedItems = 0, |
|
179 info.iTotalItems = 0; |
|
180 info.iService = ECmServiceNone; |
|
181 |
|
182 TCmProgressInfoPckg transferInfoPckg( info ); |
|
183 |
|
184 RProperty::Set( KCmPropertyCat, KCmProperty, |
|
185 transferInfoPckg ); |
|
186 |
|
187 // we aren't allowed to set wlan scanning in offline mode |
|
188 if ( GetCurrentProfileL() != KOfflineProfile ) |
|
189 { |
|
190 // Set wlan scanning parameters |
|
191 TInt interval = ( iSync == ECmServiceStateDisabled ? |
|
192 KWlanScanNetworkNever : KWlanScanNetworkInterval60 ); |
|
193 |
|
194 CmCommonUtils::SetWlanScanL( interval ); |
|
195 } |
|
196 } |
|
197 |
|
198 else if ( realIndex == EMSMemoryManager ) |
|
199 { |
|
200 iMSEngine->SetServiceState( ECmServiceMemoryManager, |
|
201 iMemoryManager ); |
|
202 } |
|
203 else |
|
204 { |
|
205 LOG(_L("[MediaServant]\t CMSSettingItemList::\ |
|
206 HandleListBoxEventL no such item")); |
|
207 } |
|
208 } |
|
209 |
|
210 // -------------------------------------------------------------------------- |
|
211 // CAknSettingItem* CMSSettingItemList::CreateSettingItemL(TInt aIdentifier) |
|
212 // Takes care of creating actual setting items. |
|
213 // -------------------------------------------------------------------------- |
|
214 // |
|
215 CAknSettingItem* CMSSettingItemList::CreateSettingItemL( TInt aIdentifier ) |
|
216 { |
|
217 LOG(_L("[MediaServant]\t CMSSettingItemList::CreateSettingItemL")); |
|
218 |
|
219 CAknSettingItem* settingItem = NULL; |
|
220 |
|
221 // setting item is created according to aIdentifier |
|
222 switch ( aIdentifier ) |
|
223 { |
|
224 case EMSSettingsSync: |
|
225 { |
|
226 LOG(_L("[MediaServant]\t List Item: EMSSettingsSync")); |
|
227 settingItem = new (ELeave ) CAknEnumeratedTextPopupSettingItem( |
|
228 aIdentifier, |
|
229 reinterpret_cast<TInt&> (iSync) ); |
|
230 break; |
|
231 } |
|
232 |
|
233 case EMSSettingsSourceDevices: |
|
234 { |
|
235 LOG(_L("[MediaServant]\t List Item: EMSSettingsSourceDevices")); |
|
236 settingItem = CMSSettingItemDevices::NewL ( |
|
237 aIdentifier, |
|
238 iDummyText, |
|
239 *iMSEngine, |
|
240 *iStoredServers ); |
|
241 break; |
|
242 } |
|
243 |
|
244 case EMSSettingsTargetDevices: |
|
245 { |
|
246 LOG(_L("[MediaServant]\t List Item: EMSSettingsTargetDevices")); |
|
247 settingItem = CMSSettingItemDevices::NewL ( |
|
248 aIdentifier, |
|
249 iDummyText, |
|
250 *iMSEngine, |
|
251 *iStoredServers, |
|
252 ETrue ); |
|
253 break; |
|
254 } |
|
255 |
|
256 case EMSSettingsMemory: |
|
257 { |
|
258 LOG(_L("[MediaServant]\t List Item: EMSSettingsMMC")); |
|
259 settingItem = CMSSettingItemMemory::NewL ( |
|
260 aIdentifier, |
|
261 iDummyText, |
|
262 *iMSEngine, |
|
263 *this ); |
|
264 break; |
|
265 } |
|
266 |
|
267 case EMSMemoryManager: |
|
268 { |
|
269 LOG(_L("[MediaServant]\t List Item: EMSMemoryManager")); |
|
270 settingItem = new ( ELeave ) CAknBinaryPopupSettingItem( |
|
271 aIdentifier, |
|
272 reinterpret_cast<TBool&> (iMemoryManager) ); |
|
273 break; |
|
274 } |
|
275 |
|
276 default: |
|
277 { |
|
278 LOG(_L("[MediaServant]\t No list item found")); |
|
279 break; |
|
280 } |
|
281 } |
|
282 return settingItem; |
|
283 } |
|
284 |
|
285 // -------------------------------------------------------------------------- |
|
286 // CMSSettingItemList::EditItemL() |
|
287 // Called by framework when item is opened |
|
288 // -------------------------------------------------------------------------- |
|
289 // |
|
290 void CMSSettingItemList::EditItemL ( TInt aIndex, TBool aCalledFromMenu ) |
|
291 { |
|
292 CAknSettingItemList::EditItemL( aIndex, aCalledFromMenu ); |
|
293 |
|
294 if ( iListBox->CurrentItemIndex() == EMSSettingsSourceDevices ) |
|
295 { |
|
296 CMSSettingItemDevices* item = static_cast<CMSSettingItemDevices*> |
|
297 (SearchItemById( EMSSettingsSourceDevices )); |
|
298 |
|
299 if ( item->SettingAccepted() ) |
|
300 { |
|
301 TCmServerState state( ECmServerStateIdle ); |
|
302 // List of unselected servers |
|
303 RPointerArray<CCmMediaServerFull> unselectedServers; |
|
304 |
|
305 iMSEngine->ServerState( state ); |
|
306 if ( state != ECmServerStateIdle ) |
|
307 { |
|
308 iMSEngine->StopOperation(); |
|
309 } |
|
310 iView.ClearCurrentNaviPaneText(); |
|
311 |
|
312 iMSEngine->DeleteMetadataL(); |
|
313 |
|
314 HBufC* naviText = StringLoader::LoadLC( |
|
315 R_MS_PREPROCESSING_TEXT ); |
|
316 iView.SetNavigationPaneTextL( *naviText ); |
|
317 CleanupStack::PopAndDestroy( naviText ); |
|
318 } |
|
319 } |
|
320 } |
|
321 |
|
322 // -------------------------------------------------------------------------- |
|
323 // CMSSettingItemList::SearchItemById |
|
324 // Searches item from the itemarray by given ID |
|
325 // -------------------------------------------------------------------------- |
|
326 // |
|
327 CAknSettingItem* CMSSettingItemList:: |
|
328 SearchItemById( const TMSSettingItems aId ) const |
|
329 { |
|
330 LOG(_L("[MediaServant]\t CMSSettingItemList::SearchItemById")); |
|
331 |
|
332 CAknSettingItem* item = NULL; |
|
333 CAknSettingItemArray* itemArray = SettingItemArray(); |
|
334 TInt count = itemArray->Count(); |
|
335 |
|
336 for ( TInt index = 0; index < count; index++ ) |
|
337 { |
|
338 if ( itemArray->At( index )->Identifier() == aId ) |
|
339 { |
|
340 item = itemArray->At( index ); |
|
341 // end loop |
|
342 index = count; |
|
343 } |
|
344 } |
|
345 return item; |
|
346 } |
|
347 |
|
348 // -------------------------------------------------------------------------- |
|
349 // CMSSettingItemList::SizeChanged() |
|
350 // Called by framework when the view size is changed. |
|
351 // -------------------------------------------------------------------------- |
|
352 // |
|
353 void CMSSettingItemList::SizeChanged() |
|
354 { |
|
355 LOG(_L("[MediaServant]\t CMSSettingItemList::SizeChanged")); |
|
356 |
|
357 ListBox()->SetRect( Rect() ); // Set rectangle of listbox. |
|
358 } |
|
359 |
|
360 // -------------------------------------------------------------------------- |
|
361 // CMSSettingItemList::HandleResourceChange |
|
362 // Handles layout change |
|
363 // -------------------------------------------------------------------------- |
|
364 // |
|
365 void CMSSettingItemList::HandleResourceChange( TInt aType ) |
|
366 { |
|
367 LOG(_L("[MediaServant]\t CMSSettingItemList::HandleResourceChange")); |
|
368 |
|
369 if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
370 { |
|
371 SetRect( iView.ClientRect() ); |
|
372 } |
|
373 |
|
374 CCoeControl::HandleResourceChange( aType ); |
|
375 } |
|
376 |
|
377 // -------------------------------------------------------------------------- |
|
378 // CMSSettingItemList::ReadyL() |
|
379 // engine observer callback |
|
380 // -------------------------------------------------------------------------- |
|
381 // |
|
382 #ifdef __DEBUG |
|
383 void CMSSettingItemList::ReadyL( TCmService aService, TInt aError ) |
|
384 #else |
|
385 void CMSSettingItemList::ReadyL( TCmService aService, TInt /*aError*/ ) |
|
386 #endif |
|
387 { |
|
388 LOG(_L("[MediaServant]\t CMSSettingItemList::ReadyL")); |
|
389 #ifdef __DEBUG |
|
390 TRACE(Print(_L("[MediaServant]\t CMSSettingItemList::\ |
|
391 ReadyL error %d"), aError)); |
|
392 #endif |
|
393 |
|
394 |
|
395 switch ( aService ) |
|
396 { |
|
397 case ECmServiceDeleteMetadata: |
|
398 { |
|
399 iMSEngine->ExecuteFillPreProcessingL(); |
|
400 break; |
|
401 } |
|
402 case ECmServicePreProcessingFill: |
|
403 { |
|
404 iView.ClearCurrentNaviPaneText(); |
|
405 break; |
|
406 } |
|
407 default: |
|
408 { |
|
409 // do nothing |
|
410 break; |
|
411 } |
|
412 } |
|
413 } |
|
414 |
|
415 // -------------------------------------------------------------------------- |
|
416 // CMSSettingItemList::MSEngine() |
|
417 // -------------------------------------------------------------------------- |
|
418 // |
|
419 CMSEngine* CMSSettingItemList::MSEngine() |
|
420 { |
|
421 LOG(_L("[MediaServant]\t CMSSettingItemList::MSEngine")); |
|
422 |
|
423 return iMSEngine; |
|
424 } |
|
425 |
|
426 // -------------------------------------------------------------------------- |
|
427 // CMSMainContainer::GetCurrentProfileL() |
|
428 // Reads current profile |
|
429 // -------------------------------------------------------------------------- |
|
430 // |
|
431 TInt CMSSettingItemList::GetCurrentProfileL() const |
|
432 { |
|
433 LOG(_L("[MediaServant]\t CMSSettingItemList::GetCurrentProfileL")); |
|
434 |
|
435 TInt profile( 0 ); |
|
436 CRepository* repository = CRepository::NewLC( KCRUidProfileEngine ); |
|
437 repository->Get( KProEngActiveProfile, profile ); |
|
438 CleanupStack::PopAndDestroy( repository ); |
|
439 |
|
440 return profile; |
|
441 } |
|
442 |
|
443 |
|
444 // --------------------------------------------------------------------------- |
|
445 // CMSSettingItemList::SetMemorySelectionL |
|
446 // --------------------------------------------------------------------------- |
|
447 // |
|
448 void CMSSettingItemList::SetMemorySelectionL() |
|
449 { |
|
450 LOG(_L("[MediaServant]\t CMSSettingItemList::SetMemorySelectionL")); |
|
451 |
|
452 TBool memoryCardFound( EFalse ); |
|
453 RPointerArray<CCmDriveInfo> driveArray; |
|
454 CleanupClosePushL( driveArray ); |
|
455 MCmSettings* settings = CCmSettingsFactory::NewCmSettingsEngineLC(); |
|
456 |
|
457 // get available drives |
|
458 settings->DriveListL( ControlEnv()->FsSession(), driveArray ); |
|
459 settings->Close(); |
|
460 CleanupStack::Pop(); // settings |
|
461 |
|
462 TInt driveCount = driveArray.Count(); |
|
463 for ( TInt i = 0; i < driveCount; i++ ) |
|
464 { |
|
465 if ( driveArray[i]->DriveType() == DriveInfo::EDriveRemovable ) |
|
466 { |
|
467 memoryCardFound = ETrue; |
|
468 i = driveCount; // break loop |
|
469 } |
|
470 } |
|
471 if ( !memoryCardFound ) |
|
472 { |
|
473 CAknSettingItem* item = SearchItemById( EMSSettingsMemory ); |
|
474 item->SetHidden( ETrue); |
|
475 // visibility changed |
|
476 HandleChangeInItemArrayOrVisibilityL(); |
|
477 } |
|
478 |
|
479 driveArray.ResetAndDestroy(); |
|
480 CleanupStack::PopAndDestroy( &driveArray ); |
|
481 } |
|
482 |
|
483 // --------------------------------------------------------------------------- |
|
484 // CMSSettingItemList::GetHelpContext |
|
485 // --------------------------------------------------------------------------- |
|
486 // |
|
487 void CMSSettingItemList::GetHelpContext( TCoeHelpContext& aContext ) const |
|
488 { |
|
489 LOG(_L("[MediaServant]\t CMSSettingItemList::GetHelpContext")); |
|
490 |
|
491 aContext.iMajor = KUidMediaServant; |
|
492 aContext.iContext = KMSERV_HLP_SYNC_SETTINGS; |
|
493 } |
|
494 |
|
495 // End of File |