30
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 - 2010 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: Shortcut settings plug-in container.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <aknnotewrappers.h>
|
|
19 |
#include <aknlistquerydialog.h>
|
|
20 |
#include <e32cmn.h>
|
|
21 |
#include <aknradiobuttonsettingpage.h>
|
|
22 |
#include <StringLoader.h>
|
|
23 |
#include <csxhelp/ai.hlp.hrh>
|
|
24 |
#include <hlplch.h>
|
|
25 |
#include <activefavouritesdbnotifier.h>
|
|
26 |
#include <mcspluginsettingsres.rsg>
|
|
27 |
|
|
28 |
#include "mcspluginsettingscontainer.h"
|
|
29 |
#include "mcspluginsettingsmodel.h"
|
|
30 |
#include "mcspluginsettingsapplist.h"
|
|
31 |
#include "mcspluginsettingsbkmlist.h"
|
|
32 |
#include "mcspluginsettings.hrh"
|
|
33 |
#include "mcspluginuids.hrh"
|
|
34 |
|
|
35 |
_LIT( KMyMenuData, "matrixmenudata" );
|
|
36 |
|
|
37 |
// ======== MEMBER FUNCTIONS ========
|
|
38 |
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
// First-phase construction
|
|
41 |
// ---------------------------------------------------------------------------
|
|
42 |
//
|
|
43 |
CMCSPluginSettingsContainer::CMCSPluginSettingsContainer()
|
|
44 |
{
|
|
45 |
}
|
|
46 |
|
|
47 |
// ---------------------------------------------------------------------------
|
|
48 |
// Second-phase construction
|
|
49 |
// ---------------------------------------------------------------------------
|
|
50 |
//
|
|
51 |
void CMCSPluginSettingsContainer::ConstructL( const TRect& aRect )
|
|
52 |
{
|
|
53 |
iListBox = new (ELeave) CAknSettingStyleListBox;
|
|
54 |
BaseConstructL(aRect, R_AI_MCS_SETTINGS_VIEW_TITLE, NULL);
|
|
55 |
StartObservingL();
|
|
56 |
CheckMiddleSoftkeyLabel();
|
|
57 |
}
|
|
58 |
|
|
59 |
// ---------------------------------------------------------------------------
|
|
60 |
// Tells the settings container to start observing for changes
|
|
61 |
// ---------------------------------------------------------------------------
|
|
62 |
//
|
|
63 |
void CMCSPluginSettingsContainer::StartObservingL()
|
|
64 |
{
|
|
65 |
// registering to bookmarks db. changes observing
|
|
66 |
User::LeaveIfError( iBookmarkSession.Connect() );
|
|
67 |
User::LeaveIfError( iBookmarkDb.Open( iBookmarkSession, KBrowserBookmarks ) );
|
|
68 |
|
|
69 |
iBookmarkDbObserver = new (ELeave) CActiveFavouritesDbNotifier(
|
|
70 |
iBookmarkDb, *this );
|
|
71 |
iBookmarkDbObserver->Start();
|
|
72 |
|
|
73 |
// registering to mailbox db. changes observing
|
|
74 |
iMsvSession = CMsvSession::OpenAsObserverL( *this );
|
|
75 |
|
|
76 |
// registering to matrix menu events observing
|
|
77 |
iMenu.OpenL( KMyMenuData );
|
|
78 |
TInt err = iNotifier.Open( iMenu );
|
|
79 |
if ( err == KErrNone )
|
|
80 |
{
|
|
81 |
iNotifyWatcher = CMCSPluginWatcher::NewL( CMCSPluginWatcher::ENotify );
|
|
82 |
iNotifier.Notify( 0,
|
|
83 |
RMenuNotifier::EItemsAddedRemoved,
|
|
84 |
iNotifyWatcher->iStatus );
|
|
85 |
iNotifyWatcher->WatchNotify( this );
|
|
86 |
}
|
|
87 |
}
|
|
88 |
|
|
89 |
// ---------------------------------------------------------------------------
|
|
90 |
// Tells the settings container to stop observing for changes
|
|
91 |
// ---------------------------------------------------------------------------
|
|
92 |
//
|
|
93 |
void CMCSPluginSettingsContainer::StopObserving()
|
|
94 |
{
|
|
95 |
if( iBookmarkDbObserver )
|
|
96 |
{
|
|
97 |
delete iBookmarkDbObserver;
|
|
98 |
iBookmarkDbObserver = NULL;
|
|
99 |
}
|
|
100 |
iBookmarkDb.Close();
|
|
101 |
iBookmarkSession.Close();
|
|
102 |
|
|
103 |
if( iMsvSession )
|
|
104 |
{
|
|
105 |
delete iMsvSession;
|
|
106 |
iMsvSession = NULL;
|
|
107 |
}
|
|
108 |
|
|
109 |
iNotifier.Close();
|
|
110 |
iMenu.Close();
|
|
111 |
|
|
112 |
if ( iNotifyWatcher )
|
|
113 |
{
|
|
114 |
if ( iNotifyWatcher->IsActive() )
|
|
115 |
{
|
|
116 |
iNotifyWatcher->Cancel();
|
|
117 |
}
|
|
118 |
delete iNotifyWatcher;
|
|
119 |
iNotifyWatcher = NULL;
|
|
120 |
}
|
|
121 |
}
|
|
122 |
|
|
123 |
// ---------------------------------------------------------------------------
|
|
124 |
// Destructor
|
|
125 |
// ---------------------------------------------------------------------------
|
|
126 |
//
|
|
127 |
CMCSPluginSettingsContainer::~CMCSPluginSettingsContainer()
|
|
128 |
{
|
|
129 |
StopObserving();
|
|
130 |
}
|
|
131 |
|
|
132 |
// ---------------------------------------------------------------------------
|
|
133 |
// Sets pointer to settings plug-in model.
|
|
134 |
// ---------------------------------------------------------------------------
|
|
135 |
//
|
|
136 |
void CMCSPluginSettingsContainer::SetModel( CMCSPluginSettingsModel* aModel )
|
|
137 |
{
|
|
138 |
iModel = aModel;
|
|
139 |
}
|
|
140 |
|
|
141 |
// ---------------------------------------------------------------------------
|
|
142 |
// Handles a setting change command.
|
|
143 |
// ---------------------------------------------------------------------------
|
|
144 |
//
|
|
145 |
void CMCSPluginSettingsContainer::HandleChangeCommandL()
|
|
146 |
{
|
|
147 |
TInt current = iListBox->CurrentItemIndex();
|
|
148 |
TInt appListIndex = iModel->ItemId( current );
|
|
149 |
if ( appListIndex < -1 )
|
|
150 |
{
|
|
151 |
appListIndex = -1;
|
|
152 |
}
|
|
153 |
|
|
154 |
if ( iModel->Item( current ).locked )
|
|
155 |
{
|
|
156 |
HBufC* text = iCoeEnv->AllocReadResourceLC( R_AI_MCS_SETTINGS_TXT_FIXED_ITEM );
|
|
157 |
CAknInformationNote* note = new ( ELeave ) CAknInformationNote( ETrue );
|
|
158 |
note->ExecuteLD( *text );
|
|
159 |
CleanupStack::PopAndDestroy( text );
|
|
160 |
}
|
|
161 |
else
|
|
162 |
{
|
|
163 |
TInt selection( KErrNotFound );
|
|
164 |
TBool changed( EFalse );
|
|
165 |
CDesCArrayFlat* array = iCoeEnv->ReadDesC16ArrayResourceL(
|
|
166 |
R_AI_MCS_CHANGE_TO_PAGE_LBX );
|
|
167 |
CleanupStack::PushL( array );
|
|
168 |
|
|
169 |
CAknListQueryDialog* dialog = new ( ELeave ) CAknListQueryDialog( &selection );
|
|
170 |
CleanupStack::PushL( dialog );
|
|
171 |
dialog->PrepareLC( R_AI_MCS_LISTQUERY_CHANGE_TO_PAGE );
|
|
172 |
CleanupStack::Pop( dialog );
|
|
173 |
dialog->SetItemTextArray( array );
|
|
174 |
dialog->SetOwnershipType( ELbmDoesNotOwnItemArray );
|
|
175 |
if ( dialog->RunLD() )
|
|
176 |
{
|
|
177 |
|
|
178 |
TSettingItem itm = iModel->Item( current );
|
|
179 |
|
|
180 |
// user wants to select bookmark
|
|
181 |
if ( selection == 1 )
|
|
182 |
{
|
|
183 |
|
|
184 |
// if the last selected item was application, set selected item to -1
|
|
185 |
if ( itm.type == EApplication )
|
|
186 |
{
|
|
187 |
appListIndex = -1;
|
|
188 |
}
|
|
189 |
|
|
190 |
changed = HandleBookmarkChangeCommandL( appListIndex, current );
|
|
191 |
|
|
192 |
}
|
|
193 |
// user wants to select application
|
|
194 |
else if ( selection == 0 )
|
|
195 |
{
|
|
196 |
|
|
197 |
// if the last selected item was bookmark, set selected item to -1
|
|
198 |
if ( itm.type == EBookmark )
|
|
199 |
{
|
|
200 |
appListIndex = -1;
|
|
201 |
}
|
|
202 |
|
|
203 |
changed = HandleAppListChangeCommandL( appListIndex, current );
|
|
204 |
|
|
205 |
}
|
|
206 |
if ( changed )
|
|
207 |
{
|
|
208 |
ResetCurrentListL( current );
|
|
209 |
}
|
|
210 |
|
|
211 |
}
|
|
212 |
CleanupStack::PopAndDestroy( array );
|
|
213 |
}
|
|
214 |
}
|
|
215 |
|
|
216 |
// ---------------------------------------------------------------------------
|
|
217 |
// Handles a help command.
|
|
218 |
// ---------------------------------------------------------------------------
|
|
219 |
//
|
|
220 |
void CMCSPluginSettingsContainer::HandleHelpCommandL()
|
|
221 |
{
|
|
222 |
CArrayFixFlat<TCoeHelpContext>* array =
|
|
223 |
new ( ELeave ) CArrayFixFlat<TCoeHelpContext>( 1 );
|
|
224 |
CleanupStack::PushL( array );
|
|
225 |
array->AppendL( GetHelpContext() );
|
|
226 |
HlpLauncher::LaunchHelpApplicationL( CCoeEnv::Static()->WsSession(), array );
|
|
227 |
CleanupStack::Pop( array );
|
|
228 |
}
|
|
229 |
|
|
230 |
// ---------------------------------------------------------------------------
|
|
231 |
// Method for closing change dialog (app or bkm) if it is beeing shown
|
|
232 |
// ---------------------------------------------------------------------------
|
|
233 |
//
|
|
234 |
void CMCSPluginSettingsContainer::CloseChangeDialog()
|
|
235 |
{
|
|
236 |
TKeyEvent keyEvent;
|
|
237 |
|
|
238 |
keyEvent.iCode = EKeyEscape;
|
|
239 |
keyEvent.iScanCode = EStdKeyEscape;
|
|
240 |
keyEvent.iModifiers = 0;
|
|
241 |
keyEvent.iRepeats = 0;
|
|
242 |
|
|
243 |
CCoeControl* dialog = NULL;
|
|
244 |
|
|
245 |
if ( iAppListDialog )
|
|
246 |
{
|
|
247 |
dialog = static_cast< CCoeControl* >( iAppListDialog );
|
|
248 |
}
|
|
249 |
else if ( iBkmListDialog )
|
|
250 |
{
|
|
251 |
dialog = static_cast< CCoeControl* >( iBkmListDialog );
|
|
252 |
}
|
|
253 |
|
|
254 |
if ( dialog )
|
|
255 |
{
|
|
256 |
TRAP_IGNORE( dialog->OfferKeyEventL( keyEvent, EEventKey ) );
|
|
257 |
}
|
|
258 |
}
|
|
259 |
|
|
260 |
// ---------------------------------------------------------------------------
|
|
261 |
// Refreshes current list..
|
|
262 |
// ---------------------------------------------------------------------------
|
|
263 |
//
|
|
264 |
void CMCSPluginSettingsContainer::ResetCurrentListL( TInt aIndex )
|
|
265 |
{
|
|
266 |
if (iModel->MdcaCount() == 0)
|
|
267 |
{
|
|
268 |
iListBox->HandleItemRemovalL();
|
|
269 |
}
|
|
270 |
else
|
|
271 |
{
|
|
272 |
iListBox->HandleItemAdditionL();
|
|
273 |
}
|
|
274 |
|
|
275 |
iListBox->SetCurrentItemIndex( aIndex );
|
|
276 |
CheckMiddleSoftkeyLabel();
|
|
277 |
}
|
|
278 |
|
|
279 |
// ---------------------------------------------------------------------------
|
|
280 |
// From class MMsvSessionObserver.
|
|
281 |
// Handles an event from the message server.
|
|
282 |
// ---------------------------------------------------------------------------
|
|
283 |
//
|
|
284 |
void CMCSPluginSettingsContainer::HandleSessionEventL(
|
|
285 |
TMsvSessionEvent aEvent,
|
|
286 |
TAny* /*aArg1*/,
|
|
287 |
TAny* /*aArg2*/,
|
|
288 |
TAny* /*aArg3*/ )
|
|
289 |
{
|
|
290 |
switch ( aEvent )
|
|
291 |
{
|
|
292 |
case EMsvEntriesCreated:
|
|
293 |
// fall-through intended here
|
|
294 |
case EMsvEntriesDeleted:
|
|
295 |
// fall-through intended here
|
|
296 |
case EMsvEntriesChanged:
|
|
297 |
{
|
|
298 |
iModel->UpdateAppListL();
|
|
299 |
}
|
|
300 |
break;
|
|
301 |
default:
|
|
302 |
break;
|
|
303 |
}
|
|
304 |
}
|
|
305 |
|
|
306 |
// ---------------------------------------------------------------------------
|
|
307 |
// From CGSBaseContainer
|
|
308 |
// Constructs the settings listbox.
|
|
309 |
// ---------------------------------------------------------------------------
|
|
310 |
//
|
|
311 |
void CMCSPluginSettingsContainer::ConstructListBoxL(TInt /*aResLbxId*/)
|
|
312 |
{
|
|
313 |
iListBox->ConstructL(this, EAknListBoxSelectionList);
|
|
314 |
// Set empty listbox's text.
|
|
315 |
iListBox->View()->SetListEmptyTextL(KNullDesC);
|
|
316 |
iListBox->Model()->SetItemTextArray(iModel);
|
|
317 |
iListBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
|
|
318 |
}
|
|
319 |
|
|
320 |
// ---------------------------------------------------------------------------
|
|
321 |
// Handles a setting change command to select application from a list.
|
|
322 |
// ---------------------------------------------------------------------------
|
|
323 |
//
|
|
324 |
TBool CMCSPluginSettingsContainer::HandleAppListChangeCommandL( const TInt& aIndex,
|
|
325 |
const TInt& aSettingIndex )
|
|
326 |
{
|
|
327 |
|
|
328 |
TBool changed = EFalse;
|
|
329 |
|
|
330 |
TInt index = aIndex;
|
|
331 |
TInt oldIndex = index;
|
|
332 |
|
|
333 |
iAppListDialog = new (ELeave) CAknRadioButtonSettingPage(
|
|
334 |
R_AI_MCS_SETTINGS_APPLIST_PAGE, index, iModel->AppList());
|
|
335 |
|
|
336 |
HBufC* title = StringLoader::LoadLC( R_AI_MCS_SETTINGS_TXT_LINKN, aSettingIndex + 1, iCoeEnv );
|
|
337 |
iAppListDialog->SetSettingTextL( title->Des() );
|
|
338 |
iAppListDialog->ConstructL();
|
|
339 |
|
|
340 |
if (iAppListDialog->ExecuteLD(CAknSettingPage::EUpdateWhenChanged) &&
|
|
341 |
index != oldIndex)
|
|
342 |
{
|
|
343 |
changed = iModel->ReplaceItemL( aSettingIndex, index , EApplication );
|
|
344 |
}
|
|
345 |
|
|
346 |
CleanupStack::PopAndDestroy( title );
|
|
347 |
iAppListDialog = NULL;
|
|
348 |
|
|
349 |
return changed;
|
|
350 |
}
|
|
351 |
|
|
352 |
// ---------------------------------------------------------------------------
|
|
353 |
// Chandles a setting change command to select bookmark from a list.
|
|
354 |
// ---------------------------------------------------------------------------
|
|
355 |
//
|
|
356 |
TBool CMCSPluginSettingsContainer::HandleBookmarkChangeCommandL( const TInt& aIndex,
|
|
357 |
const TInt& aSettingIndex )
|
|
358 |
{
|
|
359 |
TBool changed = EFalse;
|
|
360 |
|
|
361 |
TInt index = aIndex;
|
|
362 |
TInt oldIndex = index;
|
|
363 |
|
|
364 |
iBkmListDialog = new (ELeave) CAknRadioButtonSettingPage(
|
|
365 |
R_AI_MCS_SETTINGS_APPLIST_PAGE, index, iModel->BkmList());
|
|
366 |
|
|
367 |
HBufC* title = StringLoader::LoadLC( R_AI_MCS_SETTINGS_TXT_LINKN, aSettingIndex + 1, iCoeEnv );
|
|
368 |
iBkmListDialog->SetSettingTextL( title->Des() );
|
|
369 |
iBkmListDialog->ConstructL();
|
|
370 |
|
|
371 |
if (iBkmListDialog->ExecuteLD(CAknSettingPage::EUpdateWhenChanged) &&
|
|
372 |
index != oldIndex)
|
|
373 |
{
|
|
374 |
changed = iModel->ReplaceItemL( aSettingIndex, index , EBookmark );
|
|
375 |
}
|
|
376 |
|
|
377 |
CleanupStack::PopAndDestroy( title );
|
|
378 |
iBkmListDialog = NULL;
|
|
379 |
return changed;
|
|
380 |
}
|
|
381 |
|
|
382 |
// ---------------------------------------------------------------------------
|
|
383 |
// Gets Help
|
|
384 |
// ---------------------------------------------------------------------------
|
|
385 |
//
|
|
386 |
TCoeHelpContext CMCSPluginSettingsContainer::GetHelpContext() const
|
|
387 |
{
|
|
388 |
TUid uid = TUid::Uid( AI_UID_ECOM_DLL_SETTINGS_MCSPLUGIN );
|
|
389 |
TCoeContextName helpString;
|
|
390 |
|
|
391 |
helpString.Copy( KSET_HLP_HOME_SCREEN_SHORTCUTS );
|
|
392 |
|
|
393 |
// set UID and topic of Help to display
|
|
394 |
return TCoeHelpContext( uid, helpString );
|
|
395 |
}
|
|
396 |
|
|
397 |
// ---------------------------------------------------------------------------
|
|
398 |
// Offers a key event.
|
|
399 |
// ---------------------------------------------------------------------------
|
|
400 |
//
|
|
401 |
TKeyResponse CMCSPluginSettingsContainer::OfferKeyEventL(
|
|
402 |
const TKeyEvent& aKeyEvent, TEventCode aType)
|
|
403 |
{
|
|
404 |
switch (aKeyEvent.iCode)
|
|
405 |
{
|
|
406 |
case EKeyLeftArrow:
|
|
407 |
case EKeyRightArrow:
|
|
408 |
// Listbox takes all event even if it doesn't use them:
|
|
409 |
return EKeyWasNotConsumed;
|
|
410 |
|
|
411 |
default:
|
|
412 |
break;
|
|
413 |
}
|
|
414 |
// Now it's iListBox's job to process the key event
|
|
415 |
return iListBox->OfferKeyEventL(aKeyEvent, aType);
|
|
416 |
}
|
|
417 |
|
|
418 |
// ---------------------------------------------------------------------------
|
|
419 |
// Checks if there is a need to update the middle softkey label.
|
|
420 |
// ---------------------------------------------------------------------------
|
|
421 |
//
|
|
422 |
void CMCSPluginSettingsContainer::CheckMiddleSoftkeyLabel()
|
|
423 |
{
|
|
424 |
CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
|
|
425 |
if (cba)
|
|
426 |
{
|
|
427 |
cba->MakeCommandVisible(EAiScutSettingsCmdChange, (iModel->MdcaCount() != 0));
|
|
428 |
}
|
|
429 |
}
|
|
430 |
|
|
431 |
// -----------------------------------------------------------------------------
|
|
432 |
// From class MFavouritesDbObserver.
|
|
433 |
// Handles database event.
|
|
434 |
// -----------------------------------------------------------------------------
|
|
435 |
//
|
|
436 |
void CMCSPluginSettingsContainer::HandleFavouritesDbEventL(RDbNotifier::TEvent aEvent)
|
|
437 |
{
|
|
438 |
switch ( aEvent )
|
|
439 |
{
|
|
440 |
case RDbNotifier::ECommit :
|
|
441 |
// fall-through intended here
|
|
442 |
case RDbNotifier::ERecover :
|
|
443 |
// fall-through intended here
|
|
444 |
case RDbNotifier::ERollback :
|
|
445 |
{
|
|
446 |
CloseChangeDialog();
|
|
447 |
iModel->UpdateBkmListL();
|
|
448 |
}
|
|
449 |
break;
|
|
450 |
default:
|
|
451 |
break;
|
|
452 |
}
|
|
453 |
}
|
|
454 |
|
|
455 |
// -----------------------------------------------------------------------------
|
|
456 |
// From class MMCSPluginWatcherObserver.
|
|
457 |
// Handles matrix menu event.
|
|
458 |
// -----------------------------------------------------------------------------
|
|
459 |
//
|
|
460 |
void CMCSPluginSettingsContainer::HandleNotifyL()
|
|
461 |
{
|
|
462 |
CloseChangeDialog();
|
|
463 |
|
|
464 |
iModel->UpdateAppListL();
|
|
465 |
ResetCurrentListL(0);
|
|
466 |
|
|
467 |
// Notification must be activated again
|
|
468 |
iNotifyWatcher->Cancel();
|
|
469 |
iNotifier.Notify( 0,
|
|
470 |
RMenuNotifier::EItemsAddedRemoved,
|
|
471 |
iNotifyWatcher->iStatus );
|
|
472 |
iNotifyWatcher->WatchNotify( this );
|
|
473 |
}
|
|
474 |
|
|
475 |
// End of File.
|