116
|
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: File containing application list classes
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
//INCLUDES:
|
|
19 |
#include <fbs.h>
|
125
|
20 |
#include <apgcli.h>
|
116
|
21 |
|
127
|
22 |
#include "tsutils.h"
|
116
|
23 |
#include "tsdatalist.h"
|
|
24 |
#include "tsscreenshotmsg.h"
|
|
25 |
#include "tsunregscreenshotmsg.h"
|
125
|
26 |
#include "tsresourcemanager.h"
|
|
27 |
#include "tsrunningapp.h"
|
|
28 |
#include "tsrunningappstorage.h"
|
127
|
29 |
#include "tsiconprovider.h"
|
|
30 |
#include "tsidlist.h"
|
116
|
31 |
|
|
32 |
// ================= MEMBER FUNCTIONS =======================
|
|
33 |
|
|
34 |
// --------------------------------------------------------------------------
|
|
35 |
/**
|
|
36 |
* Two-phased constructor.
|
|
37 |
*/
|
|
38 |
CTsDataList* CTsDataList::NewL( MTsResourceManager& aResources,
|
119
|
39 |
MTsDataObserver& aObserver,
|
|
40 |
TsEnv& aEnv )
|
116
|
41 |
{
|
|
42 |
CTsDataList* self = new (ELeave) CTsDataList( aResources,
|
119
|
43 |
aObserver,
|
|
44 |
aEnv);
|
116
|
45 |
CleanupStack::PushL( self );
|
|
46 |
self->ConstructL();
|
|
47 |
CleanupStack::Pop( self );
|
|
48 |
return self;
|
|
49 |
}
|
|
50 |
|
|
51 |
// --------------------------------------------------------------------------
|
|
52 |
/**
|
|
53 |
* Constructor.
|
|
54 |
*/
|
|
55 |
CTsDataList::CTsDataList(MTsResourceManager& aResources,
|
119
|
56 |
MTsDataObserver& aObserver,
|
|
57 |
TsEnv& aEnv)
|
116
|
58 |
:
|
125
|
59 |
CTsWindowGroupsObserverBase( aResources.WsMonitor() ),
|
116
|
60 |
iResources( aResources ),
|
119
|
61 |
iObserver( aObserver ),
|
|
62 |
iEnv( aEnv )
|
116
|
63 |
{
|
|
64 |
}
|
|
65 |
|
|
66 |
// --------------------------------------------------------------------------
|
|
67 |
/*
|
|
68 |
* Destructor
|
|
69 |
*/
|
|
70 |
CTsDataList::~CTsDataList()
|
|
71 |
{
|
|
72 |
iData.ResetAndDestroy();
|
|
73 |
iVisibleData.Close();
|
|
74 |
}
|
|
75 |
|
|
76 |
// --------------------------------------------------------------------------
|
|
77 |
/**
|
|
78 |
* Performs 2nd phase construction.
|
|
79 |
*/
|
|
80 |
void CTsDataList::ConstructL()
|
|
81 |
{
|
|
82 |
BaseConstructL();
|
|
83 |
}
|
|
84 |
|
|
85 |
// --------------------------------------------------------------------------
|
|
86 |
/**
|
|
87 |
* Returns a reference to the current content.
|
|
88 |
* Also performs sanity checks, e.g. associates application icons
|
|
89 |
* when no screenshot has been received.
|
|
90 |
* @return ref to content array
|
|
91 |
*/
|
|
92 |
const RTsFswArray& CTsDataList::Data() const
|
|
93 |
{
|
|
94 |
return iVisibleData;
|
|
95 |
}
|
|
96 |
|
|
97 |
// --------------------------------------------------------------------------
|
|
98 |
/**
|
|
99 |
* Interface implementation
|
|
100 |
* @see MTsWindowGroupsObserver HandleWindowGroupChanged
|
|
101 |
*/
|
|
102 |
void CTsDataList::HandleWindowGroupChanged(
|
119
|
103 |
MTsResourceManager &/*aResources*/,
|
|
104 |
const MTsRunningApplicationStorage& aStorage)
|
116
|
105 |
{
|
|
106 |
TRAP_IGNORE(RDebug::Print(_L("[TaskSwitcher] processing started"));
|
|
107 |
RTsFswArray newAppsList;
|
127
|
108 |
TaskSwitcher::CleanupResetAndDestroyPushL(newAppsList);
|
119
|
109 |
CollectAppsL(newAppsList, aStorage);
|
116
|
110 |
RDebug::Print(_L("[TaskSwitcher] gathered app info"));
|
|
111 |
FitDataToListL(newAppsList);
|
|
112 |
CleanupStack::PopAndDestroy(&newAppsList);
|
|
113 |
RDebug::Print(_L("[TaskSwitcher] processing finished"));
|
|
114 |
);
|
|
115 |
}
|
|
116 |
|
|
117 |
// --------------------------------------------------------------------------
|
|
118 |
/**
|
|
119 |
* Adds running apps to the list.
|
|
120 |
* @param aAppsList array to add to
|
|
121 |
*/
|
|
122 |
void CTsDataList::CollectAppsL(RTsFswArray& aAppsList,
|
119
|
123 |
const MTsRunningApplicationStorage& aStorage)
|
116
|
124 |
{
|
119
|
125 |
for( TInt i(0); i < aStorage.Count(); ++i )
|
116
|
126 |
{
|
|
127 |
TTsEntryKey key;
|
127
|
128 |
TInt err = aStorage.GenerateKey(key, aStorage[i].WindowGroupId());
|
116
|
129 |
//skip this entry if it is already on list or generate key failed
|
|
130 |
if( err!=KErrNone || FindEntry( aAppsList, key ) >= 0 )
|
|
131 |
{
|
|
132 |
continue;
|
|
133 |
}
|
|
134 |
|
119
|
135 |
// get screen number (-1=console, 0=main screen, 1=cover ui)
|
116
|
136 |
TInt appScreen = 0;
|
|
137 |
TInt scrNumErr =
|
|
138 |
iResources.ApaSession().GetDefaultScreenNumber( appScreen,
|
127
|
139 |
aStorage[i].Uid() );
|
116
|
140 |
|
127
|
141 |
if( aStorage[i].Uid().iUid &&
|
|
142 |
MTsRunningApplication::None == aStorage[i].HideMode()&&
|
116
|
143 |
(appScreen == 0 || appScreen == -1) &&
|
|
144 |
scrNumErr == KErrNone )
|
|
145 |
{
|
127
|
146 |
AddEntryL(key, aStorage[i], aAppsList );
|
116
|
147 |
}
|
|
148 |
}
|
|
149 |
}
|
|
150 |
|
|
151 |
// --------------------------------------------------------------------------
|
|
152 |
/**
|
|
153 |
* Called from CollectTasksL for each entry in the task list.
|
119
|
154 |
* @param aRunningApp running application entry
|
116
|
155 |
* @param aNewList list to add to
|
|
156 |
*/
|
127
|
157 |
void CTsDataList::AddEntryL( const TTsEntryKey aKey,
|
119
|
158 |
const MTsRunningApplication& aRunningApp,
|
116
|
159 |
RTsFswArray& aNewList )
|
|
160 |
{
|
127
|
161 |
CTsRunningAppEntry* entry = CTsRunningAppEntry::NewLC(aKey,
|
|
162 |
aRunningApp,
|
|
163 |
iResources,
|
|
164 |
iObserver,
|
|
165 |
&iEnv );
|
116
|
166 |
// add to new list, ownership is transferred
|
|
167 |
aNewList.AppendL( entry );
|
|
168 |
CleanupStack::Pop( entry );
|
|
169 |
}
|
|
170 |
|
|
171 |
// --------------------------------------------------------------------------
|
|
172 |
/**
|
|
173 |
* Checks if there is an entry for same app in the content list.
|
|
174 |
* If yes then it takes some of the data for the entry that
|
|
175 |
* will correspond to the same app in the refreshed content list.
|
|
176 |
* @param aKey new key in content list
|
|
177 |
* @return ETrue if app was found
|
|
178 |
*/
|
127
|
179 |
TBool CTsDataList::ConsiderOldData( const TTsEntryKey& aKey )
|
116
|
180 |
{
|
|
181 |
for(TInt entryIdx = 0, oldCount = iData.Count(); entryIdx < oldCount; ++entryIdx)
|
|
182 |
{
|
127
|
183 |
if (iData[entryIdx]->Key().Key() == aKey.Key())
|
116
|
184 |
{
|
|
185 |
return ETrue;
|
|
186 |
}
|
|
187 |
}
|
|
188 |
return EFalse;
|
|
189 |
}
|
|
190 |
|
|
191 |
// --------------------------------------------------------------------------
|
|
192 |
/**
|
|
193 |
* Fit existing class contained data list into give one.
|
|
194 |
* Data is being changed with application type consideration that is based
|
|
195 |
* on aConsiderWidgets param.
|
|
196 |
* Function removes or add entries into data depend on given list.
|
|
197 |
* @param aListToFit list with actual data
|
|
198 |
*/
|
|
199 |
void CTsDataList::FitDataToListL( RTsFswArray& aListToFit )
|
|
200 |
{
|
|
201 |
TBool changed = EFalse;
|
|
202 |
TInt dataCount = iData.Count();
|
|
203 |
|
|
204 |
//remove items that dont't exists in newly collected list
|
|
205 |
for (TInt i = dataCount - 1; i >= 0; --i)
|
|
206 |
{
|
127
|
207 |
if( !CheckIfExistsL( *iData[i], aListToFit ) )
|
116
|
208 |
{
|
|
209 |
delete iData[i];
|
|
210 |
iData.Remove( i );
|
|
211 |
changed = ETrue;
|
|
212 |
}
|
|
213 |
}
|
|
214 |
RArray<TTsEntryKey> allKeys;
|
|
215 |
|
|
216 |
//add new items at start
|
|
217 |
for(TInt i = aListToFit.Count() - 1; i >= 0; --i)
|
|
218 |
{
|
|
219 |
User::LeaveIfError( allKeys.Insert(aListToFit[i]->Key(), 0) );
|
127
|
220 |
if( !CheckIfExistsL( *aListToFit[i], iData ) )
|
116
|
221 |
{
|
|
222 |
HideEntryIfNotAllowed( aListToFit[i] );
|
|
223 |
User::LeaveIfError( iData.Insert( aListToFit[i], 0 ) );
|
127
|
224 |
iData[0]->RefreshTimestamp();
|
116
|
225 |
aListToFit[i] = 0;
|
|
226 |
changed = ETrue;
|
|
227 |
}
|
|
228 |
}
|
|
229 |
//establish order
|
127
|
230 |
TBool orderChanged = EstablishOrderL( allKeys );
|
116
|
231 |
//update entries data
|
|
232 |
TBool dataChanged = UpdateEntryData( aListToFit );
|
|
233 |
RebuildVisibleDataListL();
|
|
234 |
if( changed || orderChanged || dataChanged )
|
|
235 |
{
|
|
236 |
iObserver.DataChanged();
|
|
237 |
}
|
|
238 |
allKeys.Close();
|
|
239 |
}
|
|
240 |
|
|
241 |
// --------------------------------------------------------------------------
|
|
242 |
/**
|
|
243 |
* Checks if there is an entry for same app in the given list.
|
|
244 |
* @param aEntry entry
|
|
245 |
* @param aList ref to list
|
|
246 |
* @return ETrue if app was found
|
|
247 |
*/
|
|
248 |
|
127
|
249 |
TBool CTsDataList::CheckIfExistsL( const MTsEntry& aEntry,
|
116
|
250 |
const RTsFswArray& aList ) const
|
|
251 |
{
|
|
252 |
return 0 <= FindEntry( aList, aEntry.Key() );
|
|
253 |
}
|
|
254 |
|
|
255 |
// --------------------------------------------------------------------------
|
|
256 |
TBool CTsDataList::IsSupported( TInt aFunction ) const
|
|
257 |
{
|
|
258 |
return ( RegisterScreenshotMessage == aFunction ||
|
|
259 |
UnregisterScreenshotMessage == aFunction ||
|
|
260 |
WindowGroupToBackgroundMessage == aFunction );
|
|
261 |
}
|
|
262 |
|
|
263 |
// --------------------------------------------------------------------------
|
|
264 |
void CTsDataList::HandleDataL( TInt aFunction, RReadStream& aDataStream )
|
|
265 |
{
|
|
266 |
switch( aFunction )
|
|
267 |
{
|
|
268 |
case RegisterScreenshotMessage:
|
|
269 |
RegisterScreenshotL( aDataStream );
|
|
270 |
break;
|
|
271 |
case UnregisterScreenshotMessage:
|
|
272 |
UnregisterScreenshotL( aDataStream );
|
|
273 |
break;
|
|
274 |
case WindowGroupToBackgroundMessage:
|
|
275 |
UpdateTaskTimestampL( aDataStream );
|
|
276 |
break;
|
|
277 |
}
|
|
278 |
}
|
|
279 |
|
|
280 |
// --------------------------------------------------------------------------
|
127
|
281 |
MTsEntry& CTsDataList::FindL(TTsEntryKey& aKey)
|
|
282 |
{
|
|
283 |
MTsEntry* entry(0);
|
|
284 |
for(TInt offset(0); 0 == entry && offset < iData.Count(); ++offset)
|
|
285 |
{
|
|
286 |
if(iData[offset]->Key().Key() == aKey.Key())
|
|
287 |
{
|
|
288 |
entry = iData[offset];
|
|
289 |
}
|
|
290 |
}
|
|
291 |
User::LeaveIfNull(entry);
|
|
292 |
return *entry;
|
|
293 |
}
|
|
294 |
|
|
295 |
// --------------------------------------------------------------------------
|
116
|
296 |
void CTsDataList::RegisterScreenshotL( RReadStream& aDataStream )
|
|
297 |
{
|
|
298 |
CTsScreenshotMsg* msg = CTsScreenshotMsg::NewLC( aDataStream );
|
127
|
299 |
const TInt pos = FindEntry(iData, GenerateKeyL(msg->WindowGroupId() ) );
|
116
|
300 |
User::LeaveIfError(pos);
|
|
301 |
iData[pos]->SetScreenshotL( msg->Screenshot(), msg->Priority(), msg->Rotation() );
|
|
302 |
CleanupStack::PopAndDestroy(msg);
|
|
303 |
}
|
|
304 |
// --------------------------------------------------------------------------
|
|
305 |
void CTsDataList::UnregisterScreenshotL(RReadStream& aDataStream)
|
|
306 |
{
|
|
307 |
CTsUnregisterScreenshotMsg* msg =
|
|
308 |
CTsUnregisterScreenshotMsg::NewLC(aDataStream);
|
|
309 |
const TInt pos = FindEntry( iData, GenerateKeyL(msg->windowGroupId() ) );
|
|
310 |
User::LeaveIfError(pos);
|
|
311 |
iData[pos]->RemoveScreenshotL();
|
|
312 |
CleanupStack::PopAndDestroy(msg);
|
|
313 |
}
|
127
|
314 |
|
116
|
315 |
// --------------------------------------------------------------------------
|
|
316 |
void CTsDataList::UpdateTaskTimestampL( RReadStream& aDataStream )
|
|
317 |
{
|
|
318 |
const TInt wgId = aDataStream.ReadInt32L();
|
|
319 |
const TInt pos = FindEntry( iData, GenerateKeyL( wgId ) );
|
|
320 |
User::LeaveIfError( pos );
|
|
321 |
|
127
|
322 |
iData[pos]->RefreshTimestamp();
|
116
|
323 |
|
|
324 |
iObserver.DataChanged();
|
|
325 |
}
|
|
326 |
|
|
327 |
// --------------------------------------------------------------------------
|
|
328 |
/**
|
|
329 |
* Finds entry in array
|
|
330 |
* @param aList list to find
|
|
331 |
* @param aKey finding key
|
|
332 |
* @return position or KErrNotFound
|
|
333 |
*/
|
|
334 |
TInt CTsDataList::FindEntry( const RTsFswArray& aList,
|
|
335 |
const TTsEntryKey& aKey ) const
|
|
336 |
{
|
|
337 |
TInt pos(KErrNotFound);
|
|
338 |
for(TInt entryIdx = 0;
|
|
339 |
entryIdx < aList.Count() && KErrNotFound == pos;
|
|
340 |
++entryIdx)
|
|
341 |
{
|
127
|
342 |
if (aList[entryIdx]->Key().Key() == aKey.Key())
|
116
|
343 |
{
|
|
344 |
pos = entryIdx;
|
|
345 |
}
|
|
346 |
}
|
|
347 |
return pos;
|
|
348 |
}
|
|
349 |
|
|
350 |
// --------------------------------------------------------------------------
|
|
351 |
/**
|
|
352 |
* Establish entry order accridung to aKeyList, all keys MUST be in iData
|
|
353 |
* @param aKeyList reference key list
|
|
354 |
* @return ETrue if changes occured
|
|
355 |
*/
|
127
|
356 |
TBool CTsDataList::EstablishOrderL( const RArray<TTsEntryKey>& aKeyList )
|
116
|
357 |
{
|
|
358 |
TBool changed( EFalse );
|
|
359 |
TInt lastChangedItem( KErrNotFound );
|
|
360 |
__ASSERT_ALWAYS( iData.Count() == aKeyList.Count(), User::Panic(_L("EstablishOrder 1"), KErrBadHandle) );
|
|
361 |
for (TInt i = 0; i < aKeyList.Count(); i++)
|
|
362 |
{
|
|
363 |
const TTsEntryKey& currentdataKey = iData[i]->Key();
|
|
364 |
const TTsEntryKey& referenceKey = aKeyList[i];
|
|
365 |
if( !(currentdataKey == referenceKey) )
|
|
366 |
{
|
|
367 |
TInt foundPos = FindEntry( iData, referenceKey );
|
|
368 |
__ASSERT_ALWAYS(foundPos>=0, User::Panic(_L("EstablishOrder 2"), KErrBadHandle));
|
127
|
369 |
CTsRunningAppEntry* entry = iData[foundPos];
|
116
|
370 |
iData.Remove( foundPos );
|
|
371 |
iData.Insert( entry, i );
|
|
372 |
changed = ETrue;
|
|
373 |
lastChangedItem = i;
|
|
374 |
}
|
|
375 |
}
|
|
376 |
for (TInt i = lastChangedItem; i >= 0; --i)
|
|
377 |
{
|
127
|
378 |
iData[i]->RefreshTimestamp();
|
116
|
379 |
}
|
|
380 |
return changed;
|
|
381 |
}
|
|
382 |
|
|
383 |
// --------------------------------------------------------------------------
|
|
384 |
/**
|
|
385 |
* Updates entry data on mData according to list
|
|
386 |
* @param aList reference entires list
|
|
387 |
* @return ETrue if changes occured
|
|
388 |
*/
|
|
389 |
TBool CTsDataList::UpdateEntryData( const RTsFswArray& aList )
|
|
390 |
{
|
|
391 |
__ASSERT_ALWAYS( iData.Count() == aList.Count(),
|
|
392 |
User::Panic(_L("UpdateEntryData 1"), KErrBadHandle) );
|
|
393 |
TBool changed( EFalse );
|
|
394 |
for( TInt i=0; i<aList.Count(); i++ )
|
|
395 |
{
|
|
396 |
if(aList[i])
|
|
397 |
{
|
|
398 |
__ASSERT_ALWAYS(iData[i]->Key() == aList[i]->Key(),
|
|
399 |
User::Panic(_L("UpdateEntryData 2"), KErrBadHandle));
|
127
|
400 |
if( iData[i]->IsClosable() != aList[i]->IsClosable() )
|
116
|
401 |
{
|
127
|
402 |
iData[i]->SetCloseableApp(aList[i]->IsClosable());
|
116
|
403 |
changed = ETrue;
|
|
404 |
}
|
|
405 |
}
|
|
406 |
}
|
|
407 |
return changed;
|
|
408 |
}
|
|
409 |
|
|
410 |
// --------------------------------------------------------------------------
|
|
411 |
/**
|
|
412 |
* Function generate task key using window group id
|
|
413 |
* @param wgId - window group id of running application
|
|
414 |
* @param entry key
|
|
415 |
*/
|
|
416 |
TTsEntryKey CTsDataList::GenerateKeyL( TInt aWgId )
|
|
417 |
{
|
127
|
418 |
TTsEntryKey retVal;
|
|
419 |
iResources.WsMonitor().Storage().GenerateKey(retVal, aWgId);
|
|
420 |
return retVal;
|
|
421 |
/*RArray<RWsSession::TWindowGroupChainInfo> allWgIds;
|
116
|
422 |
CleanupClosePushL( allWgIds );
|
|
423 |
User::LeaveIfError( iResources.WsSession().WindowGroupList( 0, &allWgIds ) );
|
|
424 |
TTsEntryKey key;
|
|
425 |
User::LeaveIfError(TsEntryKeyGeneraror::Generate(key, aWgId, allWgIds.Array()));
|
|
426 |
CleanupStack::PopAndDestroy( &allWgIds );
|
127
|
427 |
return key;*/
|
116
|
428 |
}
|
|
429 |
|
|
430 |
// --------------------------------------------------------------------------
|
|
431 |
/**
|
|
432 |
* Hides entrie if exist on mHiddenUids
|
|
433 |
* @param entry
|
|
434 |
*/
|
127
|
435 |
void CTsDataList::HideEntryIfNotAllowed( CTsRunningAppEntry* aEntry )
|
116
|
436 |
{
|
127
|
437 |
if( iResources.ApplicationsBlackList().IsPresent(aEntry->Uid().iUid) )
|
116
|
438 |
{
|
127
|
439 |
aEntry->SetHidden(ETrue);
|
116
|
440 |
}
|
|
441 |
}
|
|
442 |
|
127
|
443 |
// --------------------------------------------------------------------------
|
116
|
444 |
void CTsDataList::RebuildVisibleDataListL()
|
|
445 |
{
|
|
446 |
iVisibleData.Reset();
|
|
447 |
RArray<TInt> visibleItems(iData.Count() ? iData.Count() : 1);
|
|
448 |
CleanupClosePushL(visibleItems);
|
|
449 |
for( TInt iter = 0; iter < iData.Count(); ++iter )
|
|
450 |
{
|
127
|
451 |
if( MTsRunningApplication::None == iData[iter]->HideMode() )
|
116
|
452 |
{
|
|
453 |
visibleItems.AppendL(iter);
|
|
454 |
}
|
|
455 |
}
|
|
456 |
for( TInt iter = 0; iter < visibleItems.Count(); ++iter )
|
|
457 |
{
|
|
458 |
iVisibleData.AppendL( iData[visibleItems[iter]] );
|
|
459 |
}
|
|
460 |
CleanupStack::PopAndDestroy(&visibleItems);
|
|
461 |
}
|
|
462 |
// end of file
|