56
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2007 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: Container for Main View.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
|
|
22 |
// Psln specific.
|
|
23 |
#include "PslnMainViewContainer.h"
|
|
24 |
#include "PslnUi.h"
|
|
25 |
#include "PslnDebug.h"
|
|
26 |
#include "PslnConst.h"
|
|
27 |
|
|
28 |
// Lists & Icons.
|
|
29 |
#include <aknlists.h>
|
|
30 |
#include <AknIconArray.h>
|
|
31 |
#include <eikclbd.h>
|
|
32 |
|
|
33 |
// Framework
|
|
34 |
#include <pslnfwplugininterface.h>
|
|
35 |
#include "PslnPluginHandler.h"
|
|
36 |
|
|
37 |
// Resources
|
|
38 |
#include <psln.rsg>
|
|
39 |
#include <pslnicon.mbg>
|
|
40 |
#include <data_caging_path_literals.hrh>
|
|
41 |
|
|
42 |
// Help related.
|
|
43 |
#include <csxhelp/skins.hlp.hrh>
|
|
44 |
|
|
45 |
// CONSTANTS
|
|
46 |
// Tab character.
|
|
47 |
_LIT( KTab, "\t" );
|
|
48 |
|
|
49 |
// Icon indexes for listbox.
|
|
50 |
const TInt KPslnGeneralId = 0;
|
|
51 |
const TInt KPslnWallpaperId = 1;
|
|
52 |
const TInt KPslnScreenSaverId = 2;
|
|
53 |
// Container granularity.
|
|
54 |
const TInt KPslnMainConGranularity = 6;
|
|
55 |
// Max index of static (i.e. non-ECOM) folder when no plugins loaded.
|
|
56 |
const TInt KPslnStaticFolderNum = 2;
|
|
57 |
|
|
58 |
// Path to icon file.
|
|
59 |
_LIT( KPslnIconFilename, "z:pslnicon.mbm" );
|
|
60 |
|
|
61 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
62 |
|
|
63 |
// ---------------------------------------------------------------------------
|
|
64 |
// C++ constructor can NOT contain any code, that might leave.
|
|
65 |
// ---------------------------------------------------------------------------
|
|
66 |
//
|
|
67 |
CPslnMainViewContainer::CPslnMainViewContainer( CPslnUi* aPslnUi )
|
|
68 |
: iPslnUi( aPslnUi )
|
|
69 |
{
|
|
70 |
}
|
|
71 |
|
|
72 |
// ---------------------------------------------------------------------------
|
|
73 |
// Destructor.
|
|
74 |
// ---------------------------------------------------------------------------
|
|
75 |
//
|
|
76 |
CPslnMainViewContainer::~CPslnMainViewContainer()
|
|
77 |
{
|
|
78 |
// iListBox is deleted in class CPslnBaseContainer.
|
|
79 |
delete iItems;
|
|
80 |
}
|
|
81 |
|
|
82 |
// ---------------------------------------------------------------------------
|
|
83 |
// Symbian 2nd phase constructor can leave.
|
|
84 |
// ---------------------------------------------------------------------------
|
|
85 |
//
|
|
86 |
void CPslnMainViewContainer::ConstructL( const TRect& aRect )
|
|
87 |
{
|
|
88 |
iListBox = new (ELeave) CAknSingleLargeStyleListBox;
|
|
89 |
|
|
90 |
BaseConstructL(
|
|
91 |
aRect,
|
|
92 |
R_PSLN_SKIN_LIST_VIEW_TITLE,
|
|
93 |
R_PSLN_MAIN_VIEW_LBX );
|
|
94 |
}
|
|
95 |
|
|
96 |
// ---------------------------------------------------------------------------
|
|
97 |
// Creates listbox.
|
|
98 |
// ---------------------------------------------------------------------------
|
|
99 |
//
|
|
100 |
void CPslnMainViewContainer::ConstructListBoxL( TInt aResLbxId )
|
|
101 |
{
|
|
102 |
iItems = iCoeEnv->ReadDesC16ArrayResourceL( aResLbxId );
|
|
103 |
CreateListBoxItemsL();
|
|
104 |
}
|
|
105 |
|
|
106 |
|
|
107 |
// ---------------------------------------------------------------------------
|
|
108 |
// Creates listbox items.
|
|
109 |
// ---------------------------------------------------------------------------
|
|
110 |
//
|
|
111 |
void CPslnMainViewContainer::CreateListBoxItemsL()
|
|
112 |
{
|
|
113 |
PSLN_TRACE_DEBUG("CPslnMainViewContainer::CreateListBoxItemsL BEGIN");
|
|
114 |
// Array for icons in the listbox. Owns the icons.
|
|
115 |
CAknIconArray* iconList =
|
|
116 |
new (ELeave) CAknIconArray( KPslnMainConGranularity );
|
|
117 |
CleanupStack::PushL( iconList );
|
|
118 |
|
|
119 |
// Find the resource file:
|
|
120 |
HBufC* iconFile = HBufC::NewLC( KMaxFileName );
|
|
121 |
TPtr fileNamePtr = iconFile->Des();
|
|
122 |
GetIconFilePath( fileNamePtr );
|
|
123 |
|
|
124 |
// Add non-plugin icons to icon group.
|
|
125 |
// General icon.
|
|
126 |
AddIconL(
|
|
127 |
iconList,
|
|
128 |
KAknsIIDQgnPropPslnGeneralSub,
|
|
129 |
fileNamePtr,
|
|
130 |
EMbmPslniconQgn_prop_psln_general_sub,
|
|
131 |
EMbmPslniconQgn_prop_psln_general_sub_mask );
|
|
132 |
|
|
133 |
// Wallpaper icon.
|
|
134 |
AddIconL(
|
|
135 |
iconList,
|
|
136 |
KAknsIIDQgnPropPslnWpaperSub,
|
|
137 |
fileNamePtr,
|
|
138 |
EMbmPslniconQgn_prop_psln_wpaper_sub,
|
|
139 |
EMbmPslniconQgn_prop_psln_wpaper_sub_mask );
|
|
140 |
|
|
141 |
// Screensaver screensaver.
|
|
142 |
AddIconL(
|
|
143 |
iconList,
|
|
144 |
KAknsIIDQgnPropPslnSsaverSub,
|
|
145 |
fileNamePtr,
|
|
146 |
EMbmPslniconQgn_prop_psln_ssaver_sub,
|
|
147 |
EMbmPslniconQgn_prop_psln_ssaver_sub_mask );
|
|
148 |
|
|
149 |
CleanupStack::PopAndDestroy( iconFile );
|
|
150 |
|
|
151 |
// Add General Theme static view.
|
|
152 |
// Icon location is ok - directly from resources.
|
|
153 |
MakeItemL( KPslnGeneralId );
|
|
154 |
|
|
155 |
// How many dynamic items have been added in-between.
|
|
156 |
TInt offset = 0;
|
|
157 |
iPluginArray = iPslnUi->PluginHandler()->GetPluginArray();
|
|
158 |
// Create buffers.
|
|
159 |
HBufC* buf = HBufC::NewLC( KPslnItemLength );
|
|
160 |
TPtr ptrBuf = buf->Des();
|
|
161 |
HBufC* item = HBufC::NewLC( KPslnItemLength );
|
|
162 |
TPtr ptrItem = item->Des();
|
|
163 |
// Add Active Idle (and Application Shell) plugin(s).
|
|
164 |
if ( iPluginArray )
|
|
165 |
{
|
|
166 |
for ( TInt i = 0; i < iPluginArray->Count(); i++ )
|
|
167 |
{
|
|
168 |
CPslnFWPluginInterface* plugin = iPluginArray->operator[]( i );
|
|
169 |
CleanupStack::PushL( plugin );
|
|
170 |
|
|
171 |
// TRAP all but OOM, so that plugins cannot cause Psln to fail to
|
|
172 |
// launch.
|
|
173 |
TRAPD( err,
|
|
174 |
offset += MakePluginItemL( *plugin, *iconList, ptrBuf, ptrItem ) );
|
|
175 |
if ( err == KErrNoMemory )
|
|
176 |
{
|
|
177 |
User::Leave( KErrNoMemory );
|
|
178 |
}
|
|
179 |
|
|
180 |
// Initialize buffers.
|
|
181 |
ptrBuf.Zero();
|
|
182 |
ptrItem.Zero();
|
|
183 |
|
|
184 |
// icon is now owned by icon array and plugin by plugin handler
|
|
185 |
CleanupStack::Pop( plugin );
|
|
186 |
plugin = NULL;
|
|
187 |
}
|
|
188 |
}
|
|
189 |
CleanupStack::PopAndDestroy( 2, buf ); // buf, item
|
|
190 |
|
|
191 |
// Add Screen Saver and Wallpaper static views.
|
|
192 |
TBitFlags views = iPslnUi->ViewSupport();
|
|
193 |
if ( views.IsSet( CPslnUi::EPslnWallpaperView ) )
|
|
194 |
{
|
|
195 |
MakeItemL( KPslnWallpaperId, offset );
|
|
196 |
}
|
|
197 |
|
|
198 |
if ( views.IsSet( CPslnUi::EPslnScreensaverView ) )
|
|
199 |
{
|
|
200 |
MakeItemL( KPslnScreenSaverId, offset );
|
|
201 |
}
|
|
202 |
|
|
203 |
iPslnUi->AllViewsDone();
|
|
204 |
|
|
205 |
// Destroy the old icons because SetIconArray() does not destroy them.
|
|
206 |
CEikColumnListBox* listbox = static_cast<CEikColumnListBox*> ( iListBox );
|
|
207 |
CArrayPtr<CGulIcon>* oldIcons =
|
|
208 |
listbox->ItemDrawer()->ColumnData()->IconArray();
|
|
209 |
if( oldIcons )
|
|
210 |
{
|
|
211 |
oldIcons->ResetAndDestroy();
|
|
212 |
delete oldIcons;
|
|
213 |
}
|
|
214 |
|
|
215 |
// Transfer ownership of icon array to the lbx.
|
|
216 |
listbox->ItemDrawer()->ColumnData()->SetIconArray( iconList );
|
|
217 |
CleanupStack::Pop( iconList );
|
|
218 |
|
|
219 |
iListBox->HandleItemAdditionL();
|
|
220 |
PSLN_TRACE_DEBUG("CPslnMainViewContainer::CreateListBoxItemsL END");
|
|
221 |
}
|
|
222 |
|
|
223 |
// ---------------------------------------------------------------------------
|
|
224 |
// Creates a specific setting item.
|
|
225 |
// ---------------------------------------------------------------------------
|
|
226 |
//
|
|
227 |
void CPslnMainViewContainer::MakeItemL( const TInt aIndex, const TInt aOffset )
|
|
228 |
{
|
|
229 |
PSLN_TRACE_DEBUG("CPslnMainViewContainer::MakeItemL BEGIN");
|
|
230 |
if ( aIndex > iItems->Count() )
|
|
231 |
{
|
|
232 |
User::Leave( KErrArgument );
|
|
233 |
}
|
|
234 |
HBufC* item = (*iItems)[aIndex].AllocLC();
|
|
235 |
// Reallocating invalidates the original string.
|
|
236 |
HBufC* reallocItem = item->ReAllocL( item->Length() + KPslnIconSize );
|
|
237 |
CleanupStack::Pop( item );
|
|
238 |
item = reallocItem;
|
|
239 |
CleanupStack::PushL( item );
|
|
240 |
reallocItem = NULL; // do not use anymore.
|
|
241 |
TPtr ptr = item->Des();
|
|
242 |
|
|
243 |
TInt wallpaperOffset = 0;
|
|
244 |
if ( aIndex == KPslnScreenSaverId
|
|
245 |
&& !iPslnUi->ViewSupport().IsSet( CPslnUi::EPslnWallpaperView ) )
|
|
246 |
{
|
|
247 |
wallpaperOffset = 1;
|
|
248 |
}
|
|
249 |
if ( aOffset != KErrNotFound )
|
|
250 |
{
|
|
251 |
iItemArray->InsertL( aIndex + aOffset - wallpaperOffset, ptr );
|
|
252 |
}
|
|
253 |
else
|
|
254 |
{
|
|
255 |
iItemArray->InsertL( aIndex - wallpaperOffset, ptr );
|
|
256 |
}
|
|
257 |
CleanupStack::PopAndDestroy( item );
|
|
258 |
PSLN_TRACE_DEBUG("CPslnMainViewContainer::MakeItemL END");
|
|
259 |
}
|
|
260 |
|
|
261 |
// ---------------------------------------------------------------------------
|
|
262 |
// Gets help context for Help application.
|
|
263 |
// ---------------------------------------------------------------------------
|
|
264 |
//
|
|
265 |
void CPslnMainViewContainer::GetHelpContext( TCoeHelpContext& aContext ) const
|
|
266 |
{
|
|
267 |
aContext.iMajor = KUidPsln;
|
|
268 |
aContext.iContext = KSKINS_HLP_APP_MAIN;
|
|
269 |
}
|
|
270 |
|
|
271 |
// ---------------------------------------------------------------------------
|
|
272 |
// Creates a plugin item (with title and icon)
|
|
273 |
// ---------------------------------------------------------------------------
|
|
274 |
//
|
|
275 |
TInt CPslnMainViewContainer::MakePluginItemL(
|
|
276 |
CPslnFWPluginInterface& aPlugin, CAknIconArray& aIconList,
|
|
277 |
TPtr& aBufPtr, TPtr& aItemPtr )
|
|
278 |
{
|
|
279 |
TInt offset = 0;
|
|
280 |
// Adding icon.
|
|
281 |
CGulIcon* icon = aPlugin.CreateIconL();
|
|
282 |
CleanupStack::PushL( icon );
|
|
283 |
PSLN_TRACE_DEBUG("CPslnMainViewContainer::MakePluginItemL BEGIN");
|
|
284 |
|
|
285 |
aPlugin.GetCaptionL( aBufPtr );
|
|
286 |
TInt location = KErrNotFound;
|
|
287 |
CPslnFWPluginInterface::TPslnFWLocationType locType;
|
|
288 |
aPlugin.GetLocationTypeAndIndex( locType, location );
|
|
289 |
|
|
290 |
// If it is AS or AI plugin, add it.
|
|
291 |
if ( aPlugin.Id().iUid == KPslnASPluginUid.iUid ||
|
|
292 |
aPlugin.Id().iUid == KPslnAIPluginUid.iUid )
|
|
293 |
{
|
|
294 |
TInt upcomingPlace = location + KPslnStaticFolderNum;
|
|
295 |
if ( upcomingPlace >= aIconList.Count() )
|
|
296 |
{
|
|
297 |
upcomingPlace = aIconList.Count();
|
|
298 |
}
|
|
299 |
aIconList.InsertL( upcomingPlace , icon );
|
|
300 |
|
|
301 |
// Let's correct the icon index.
|
|
302 |
upcomingPlace = location + KPslnStaticFolderNum;
|
|
303 |
aItemPtr.AppendNum( upcomingPlace );
|
|
304 |
aItemPtr.Append( KTab );
|
|
305 |
aItemPtr.Append( aBufPtr );
|
|
306 |
if ( location >= iItemArray->Count() )
|
|
307 |
{
|
|
308 |
location = iItemArray->Count();
|
|
309 |
}
|
|
310 |
iItemArray->InsertL( location , aItemPtr );
|
|
311 |
offset++;
|
|
312 |
}
|
|
313 |
else
|
|
314 |
{
|
|
315 |
aIconList.AppendL( icon );
|
|
316 |
// use icon list position as index
|
|
317 |
// iconList->Count() is here always at least 1
|
|
318 |
// we need to adjust the icon index based on loaded plugins
|
|
319 |
// which are inserted between static views.
|
|
320 |
aItemPtr.AppendNum( aIconList.Count() - 1 + iAIAdded + iASAdded );
|
|
321 |
aItemPtr.Append( KTab );
|
|
322 |
aItemPtr.Append( aBufPtr );
|
|
323 |
iItemArray->AppendL( aItemPtr );
|
|
324 |
}
|
|
325 |
|
|
326 |
if ( aPlugin.Id().iUid == KPslnASPluginUid.iUid )
|
|
327 |
{
|
|
328 |
iASAdded = ETrue;
|
|
329 |
}
|
|
330 |
|
|
331 |
if ( aPlugin.Id().iUid == KPslnAIPluginUid.iUid )
|
|
332 |
{
|
|
333 |
iAIAdded = ETrue;
|
|
334 |
}
|
|
335 |
|
|
336 |
CleanupStack::Pop( icon );
|
|
337 |
return offset;
|
|
338 |
}
|
|
339 |
|
|
340 |
// ---------------------------------------------------------------------------
|
|
341 |
// Adds icon to icon array.
|
|
342 |
// ---------------------------------------------------------------------------
|
|
343 |
//
|
|
344 |
void CPslnMainViewContainer::AddIconL(
|
|
345 |
CAknIconArray* aIcons,
|
|
346 |
const TAknsItemID& aSkinId,
|
|
347 |
const TDesC& aFileName,
|
|
348 |
TInt aBitmapId,
|
|
349 |
TInt aMaskId )
|
|
350 |
{
|
|
351 |
CFbsBitmap* bitmap = NULL;
|
|
352 |
CFbsBitmap* mask = NULL;
|
|
353 |
AknsUtils::CreateIconL(
|
|
354 |
AknsUtils::SkinInstance(),
|
|
355 |
aSkinId,
|
|
356 |
bitmap,
|
|
357 |
mask,
|
|
358 |
aFileName,
|
|
359 |
aBitmapId,
|
|
360 |
aMaskId );
|
|
361 |
CleanupStack::PushL( bitmap );
|
|
362 |
CleanupStack::PushL( mask );
|
|
363 |
CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
|
|
364 |
CleanupStack::Pop( 2, bitmap ); // bitmap, mask
|
|
365 |
CleanupStack::PushL( icon );
|
|
366 |
if ( aIcons )
|
|
367 |
{
|
|
368 |
aIcons->AppendL( icon );
|
|
369 |
}
|
|
370 |
CleanupStack::Pop( icon );
|
|
371 |
}
|
|
372 |
|
|
373 |
// ---------------------------------------------------------------------------
|
|
374 |
// Parses icon file path to given parameter.
|
|
375 |
// ---------------------------------------------------------------------------
|
|
376 |
//
|
|
377 |
void CPslnMainViewContainer::GetIconFilePath( TDes& aPath )
|
|
378 |
{
|
|
379 |
// Find the resource file:
|
|
380 |
TParse parse;
|
|
381 |
parse.Set( KPslnIconFilename, &KDC_APP_BITMAP_DIR, NULL );
|
|
382 |
if ( aPath.MaxLength() >= parse.FullName().Length() )
|
|
383 |
{
|
|
384 |
aPath.Copy( parse.FullName() );
|
|
385 |
}
|
|
386 |
}
|
|
387 |
|
|
388 |
// End of File
|