|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "tsrunningappmodel.h" |
|
19 |
|
20 #include <AknDef.h> |
|
21 #include <apgwgnam.h> |
|
22 #include <apgtask.h> |
|
23 |
|
24 #include "tsdatalist.h" |
|
25 #include "tsmodelobserver.h" |
|
26 #include "tsscreenshotprovider.h" |
|
27 |
|
28 CTsRunningAppModel *CTsRunningAppModel::NewL(MTsResourceManager &resources, MTsWindowGroupsMonitor &monitor) |
|
29 { |
|
30 CTsRunningAppModel *self = CTsRunningAppModel::NewLC(resources, monitor); |
|
31 CleanupStack::Pop(self); |
|
32 return self; |
|
33 } |
|
34 |
|
35 CTsRunningAppModel *CTsRunningAppModel::NewLC(MTsResourceManager &resources, MTsWindowGroupsMonitor &monitor) |
|
36 { |
|
37 CTsRunningAppModel *self = new (ELeave) CTsRunningAppModel(resources); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(resources, monitor); |
|
40 return self; |
|
41 } |
|
42 |
|
43 CTsRunningAppModel::~CTsRunningAppModel() |
|
44 { |
|
45 delete mDataList; |
|
46 delete mScreenshotProvider; |
|
47 } |
|
48 |
|
49 CTsRunningAppModel::CTsRunningAppModel(MTsResourceManager &resources) : mResources(resources) |
|
50 { |
|
51 } |
|
52 |
|
53 void CTsRunningAppModel::ConstructL(MTsResourceManager &resources, MTsWindowGroupsMonitor &monitor) |
|
54 { |
|
55 mDataList = CTsDataList::NewL(resources, monitor, *this); |
|
56 mScreenshotProvider = CTsScreenshotProvider::NewL(*mDataList); |
|
57 |
|
58 RArray<RWsSession::TWindowGroupChainInfo> wgList; |
|
59 CleanupClosePushL(wgList); |
|
60 User::LeaveIfError(resources.WsSession().WindowGroupList(0, &wgList)); |
|
61 mDataList->HandleWindowGroupChanged(resources, wgList.Array()); |
|
62 CleanupStack::PopAndDestroy(&wgList); |
|
63 } |
|
64 |
|
65 // -------------------------------------------------------------------------- |
|
66 // MHsDataObserver interface implementation |
|
67 // -------------------------------------------------------------------------- |
|
68 // |
|
69 void CTsRunningAppModel::DataChanged() |
|
70 { |
|
71 if (mObserver) { |
|
72 mObserver->dataChanged(*this); |
|
73 } |
|
74 } |
|
75 |
|
76 // -------------------------------------------------------------------------- |
|
77 // MTsTaskSettings interface implementation |
|
78 // -------------------------------------------------------------------------- |
|
79 // |
|
80 TBool CTsRunningAppModel::isSupported(TInt function) const |
|
81 { |
|
82 return mDataList->isSupported(function); |
|
83 } |
|
84 |
|
85 void CTsRunningAppModel::handleDataL(TInt function,RReadStream& dataStream) |
|
86 { |
|
87 mDataList->handleDataL(function, dataStream); |
|
88 } |
|
89 |
|
90 // -------------------------------------------------------------------------- |
|
91 // MTsModel interface implementation |
|
92 // -------------------------------------------------------------------------- |
|
93 // |
|
94 TInt CTsRunningAppModel::count() const |
|
95 { |
|
96 return mDataList->Data().Count(); |
|
97 } |
|
98 |
|
99 void CTsRunningAppModel::setObserver(MTsModelObserver *observer) |
|
100 { |
|
101 mObserver = observer; |
|
102 } |
|
103 |
|
104 const TDesC& CTsRunningAppModel::displayNameL(TInt offset) const |
|
105 { |
|
106 return mDataList->Data()[offset]->AppName(); |
|
107 } |
|
108 |
|
109 TInt CTsRunningAppModel::iconHandleL(TInt offset) const |
|
110 { |
|
111 CFbsBitmap *bitmap = mDataList->Data()[offset]->Screenshot(); |
|
112 if (!bitmap) { |
|
113 bitmap = mDataList->Data()[offset]->AppIconBitmap(); |
|
114 } |
|
115 |
|
116 if (bitmap) { |
|
117 return bitmap->Handle(); |
|
118 } else { |
|
119 return KErrNotFound; |
|
120 } |
|
121 } |
|
122 |
|
123 TTime CTsRunningAppModel::timestampL(TInt offset) const |
|
124 { |
|
125 return mDataList->Data()[offset]->Timestamp(); |
|
126 } |
|
127 |
|
128 TTsModelItemKey CTsRunningAppModel::keyL(TInt offset) const |
|
129 { |
|
130 return TTsModelItemKey(mDataList->Data()[offset]->Key().WindowGroupId(), |
|
131 reinterpret_cast<TInt>(this)); |
|
132 } |
|
133 |
|
134 TBool CTsRunningAppModel::isActiveL(TInt /*offset*/) const |
|
135 { |
|
136 return ETrue; |
|
137 } |
|
138 |
|
139 TBool CTsRunningAppModel::isClosableL(TInt offset) const |
|
140 { |
|
141 return mDataList->Data()[offset]->CloseableApp(); |
|
142 } |
|
143 |
|
144 TBool CTsRunningAppModel::closeL(TTsModelItemKey key) const |
|
145 { |
|
146 TApaTask task(mResources.WsSession()); |
|
147 task.SetWgId(key.key()); |
|
148 task.EndTask(); |
|
149 return ETrue; |
|
150 } |
|
151 |
|
152 TBool CTsRunningAppModel::launchL(TTsModelItemKey key) const |
|
153 { |
|
154 // find uid by wgid from key |
|
155 CApaWindowGroupName *windowGroupName = |
|
156 CApaWindowGroupName::NewLC(mResources.WsSession(), key.key()); |
|
157 TUid uid = windowGroupName->AppUid(); |
|
158 CleanupStack::PopAndDestroy(windowGroupName); |
|
159 |
|
160 TApaTask task = TApaTaskList(mResources.WsSession()).FindApp(uid); |
|
161 task.BringToForeground(); |
|
162 return task.Exists(); |
|
163 } |