|
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: Task list entry |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <s32strm.h> |
|
19 #include <fbs.h> |
|
20 #include <AknDef.h> |
|
21 #include <apgwgnam.h> |
|
22 #include <apgtask.h> |
|
23 #include <apgcli.h> |
|
24 |
|
25 #include "tsrunningappentry.h" |
|
26 #include "tsiconprovider.h" |
|
27 #include "tsdataobserver.h" |
|
28 #include "tsthumbnailprovider.h" |
|
29 #include "tsresourcemanager.h" |
|
30 |
|
31 // -------------------------------------------------------------------------- |
|
32 CTsRunningAppEntry* CTsRunningAppEntry::NewL(const TTsEntryKey aKey, |
|
33 const MTsRunningApplication& aCacheEntry, |
|
34 MTsResourceManager& aResources, |
|
35 MTsDataObserver &aObserver, |
|
36 QObject* aObj) |
|
37 { |
|
38 CTsRunningAppEntry* self = NewLC(aKey, |
|
39 aCacheEntry , |
|
40 aResources, |
|
41 aObserver, |
|
42 aObj); |
|
43 CleanupStack::Pop(self); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // -------------------------------------------------------------------------- |
|
48 CTsRunningAppEntry* CTsRunningAppEntry::NewLC(const TTsEntryKey aKey, |
|
49 const MTsRunningApplication& aCacheEntry, |
|
50 MTsResourceManager& aResources, |
|
51 MTsDataObserver &aObserver, |
|
52 QObject* aObj) |
|
53 { |
|
54 CTsRunningAppEntry* self = new (ELeave) CTsRunningAppEntry(aKey, |
|
55 aResources, |
|
56 aObserver); |
|
57 CleanupStack::PushL(self); |
|
58 self->ConstructL(aCacheEntry, aObj); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // -------------------------------------------------------------------------- |
|
63 CTsRunningAppEntry::~CTsRunningAppEntry() |
|
64 { |
|
65 delete iCaption; |
|
66 delete iThumbnail; |
|
67 delete iThumbnailProvider; |
|
68 } |
|
69 |
|
70 // -------------------------------------------------------------------------- |
|
71 CTsRunningAppEntry::CTsRunningAppEntry(const TTsEntryKey aKey, |
|
72 MTsResourceManager& aResources, |
|
73 MTsDataObserver &aObserver) |
|
74 : |
|
75 iResources(aResources), |
|
76 iObserver(aObserver), |
|
77 iKey(aKey) |
|
78 { |
|
79 } |
|
80 |
|
81 // -------------------------------------------------------------------------- |
|
82 void CTsRunningAppEntry::ConstructL(const MTsRunningApplication& aCacheEntry, |
|
83 QObject* aObject ) |
|
84 { |
|
85 iUid = aCacheEntry.Uid(); |
|
86 iIsSystem = aCacheEntry.IsSystem(); |
|
87 iHideMode = aCacheEntry.HideMode(); |
|
88 iWindowGroupId = aCacheEntry.WindowGroupId(); |
|
89 iParentWindowGroupId = aCacheEntry.ParentWindowGroupId(); |
|
90 iTimestamp.UniversalTime(); |
|
91 iUpdateTimestamp.UniversalTime(); |
|
92 CreateDisplayNameL(aCacheEntry); |
|
93 QT_TRYCATCH_LEAVING( |
|
94 iThumbnailProvider = new TsThumbnailProvider(*this, aObject); |
|
95 ) |
|
96 } |
|
97 |
|
98 // -------------------------------------------------------------------------- |
|
99 void CTsRunningAppEntry::CreateDisplayNameL(const MTsRunningApplication& aCacheEntry) |
|
100 { |
|
101 TApaAppInfo info; |
|
102 iResources.ApaSession().GetAppInfo( info, aCacheEntry.Uid() ); |
|
103 TPtrC caption = info.iShortCaption; |
|
104 |
|
105 if (!caption.Length() ) // if not set - use thread name instead |
|
106 { |
|
107 if( aCacheEntry.DisplayName().Length() ) |
|
108 { |
|
109 iCaption = aCacheEntry.DisplayName().AllocL(); |
|
110 } |
|
111 else |
|
112 { |
|
113 TThreadId threadId; |
|
114 if(KErrNone == iResources.WsSession().GetWindowGroupClientThreadId( aCacheEntry.WindowGroupId(), threadId ) ) |
|
115 { |
|
116 RThread thread; |
|
117 CleanupClosePushL( thread ); |
|
118 if( KErrNone == thread.Open( threadId ) ) |
|
119 { |
|
120 iCaption = thread.Name().AllocL(); |
|
121 } |
|
122 CleanupStack::PopAndDestroy( &thread ); |
|
123 } |
|
124 } |
|
125 } |
|
126 else |
|
127 { |
|
128 iCaption = caption.AllocL(); |
|
129 } |
|
130 } |
|
131 |
|
132 // -------------------------------------------------------------------------- |
|
133 TUid CTsRunningAppEntry::Uid()const |
|
134 { |
|
135 return iUid; |
|
136 } |
|
137 // -------------------------------------------------------------------------- |
|
138 MTsRunningApplication::ApplicationHideMode CTsRunningAppEntry::HideMode() const |
|
139 { |
|
140 return iHideMode; |
|
141 } |
|
142 |
|
143 // -------------------------------------------------------------------------- |
|
144 void CTsRunningAppEntry::SetHidden( TBool aHidden ) |
|
145 { |
|
146 iHideMode = aHidden ? MTsRunningApplication::Software : |
|
147 MTsRunningApplication::None; |
|
148 } |
|
149 |
|
150 // -------------------------------------------------------------------------- |
|
151 TBool CTsRunningAppEntry::IsSystem() const |
|
152 { |
|
153 return iIsSystem; |
|
154 } |
|
155 |
|
156 // -------------------------------------------------------------------------- |
|
157 TInt CTsRunningAppEntry::WindowGroupId() const |
|
158 { |
|
159 return iWindowGroupId; |
|
160 } |
|
161 |
|
162 // -------------------------------------------------------------------------- |
|
163 TInt CTsRunningAppEntry::ParentWindowGroupId() const |
|
164 { |
|
165 return iParentWindowGroupId; |
|
166 } |
|
167 |
|
168 // -------------------------------------------------------------------------- |
|
169 TBool CTsRunningAppEntry::IsEmbeded() const |
|
170 { |
|
171 return (0 >= iParentWindowGroupId); |
|
172 } |
|
173 |
|
174 // -------------------------------------------------------------------------- |
|
175 const TDesC& CTsRunningAppEntry::DisplayName() const |
|
176 { |
|
177 return iCaption ? *iCaption : KNullDesC(); |
|
178 } |
|
179 |
|
180 // -------------------------------------------------------------------------- |
|
181 TInt CTsRunningAppEntry::IconHandle() const |
|
182 { |
|
183 if( 0 == iThumbnail ) |
|
184 { |
|
185 TRAP_IGNORE( CFbsBitmap *icon(new(ELeave) CFbsBitmap()); |
|
186 CleanupStack::PushL(icon); |
|
187 iResources.IconProvider().LoadIconL(*icon, Uid()); |
|
188 CleanupStack::Pop(icon); |
|
189 iThumbnail = icon;) |
|
190 } |
|
191 return iThumbnail ? iThumbnail->Handle() : KErrNotFound; |
|
192 } |
|
193 // -------------------------------------------------------------------------- |
|
194 TTime CTsRunningAppEntry::Timestamp() const |
|
195 { |
|
196 return iTimestamp; |
|
197 } |
|
198 |
|
199 // -------------------------------------------------------------------------- |
|
200 TTime CTsRunningAppEntry::TimestampUpdate() const |
|
201 { |
|
202 return iUpdateTimestamp; |
|
203 } |
|
204 |
|
205 // -------------------------------------------------------------------------- |
|
206 TTsEntryKey CTsRunningAppEntry::Key() const |
|
207 { |
|
208 return iKey; |
|
209 } |
|
210 |
|
211 // -------------------------------------------------------------------------- |
|
212 TBool CTsRunningAppEntry::IsActive() const |
|
213 { |
|
214 return true; |
|
215 } |
|
216 |
|
217 // -------------------------------------------------------------------------- |
|
218 TBool CTsRunningAppEntry::IsClosable() const |
|
219 { |
|
220 return !iIsSystem; |
|
221 } |
|
222 |
|
223 // -------------------------------------------------------------------------- |
|
224 TBool CTsRunningAppEntry::Close() const |
|
225 { |
|
226 TApaTask task( iResources.WsSession() ); |
|
227 task.SetWgId( WindowGroupId() ); |
|
228 task.EndTask(); |
|
229 return ETrue; |
|
230 } |
|
231 |
|
232 // -------------------------------------------------------------------------- |
|
233 TBool CTsRunningAppEntry::Launch() const |
|
234 { |
|
235 TApaTask task = TApaTaskList( iResources.WsSession() ).FindApp( iUid ); |
|
236 task.BringToForeground(); |
|
237 return task.Exists(); |
|
238 } |
|
239 |
|
240 // -------------------------------------------------------------------------- |
|
241 TBool CTsRunningAppEntry::IsMandatory() const |
|
242 { |
|
243 return ETrue; |
|
244 } |
|
245 |
|
246 // -------------------------------------------------------------------------- |
|
247 void CTsRunningAppEntry::RefreshTimestamp() |
|
248 { |
|
249 iTimestamp.UniversalTime(); |
|
250 RefreshUpdateTimestamp(); |
|
251 } |
|
252 |
|
253 // -------------------------------------------------------------------------- |
|
254 /** |
|
255 * Set new value of updates timestamp |
|
256 */ |
|
257 void CTsRunningAppEntry::RefreshUpdateTimestamp() |
|
258 { |
|
259 iUpdateTimestamp.UniversalTime(); |
|
260 } |
|
261 |
|
262 // -------------------------------------------------------------------------- |
|
263 void CTsRunningAppEntry::SetCloseableApp(TBool aClosable) |
|
264 { |
|
265 iIsSystem = !aClosable; |
|
266 } |
|
267 |
|
268 // -------------------------------------------------------------------------- |
|
269 // CTsFswEntry::SetScreenshot |
|
270 // -------------------------------------------------------------------------- |
|
271 // |
|
272 void CTsRunningAppEntry::SetScreenshotL(const CFbsBitmap &bitmapArg, UpdatePriority priority, TInt angle) |
|
273 { |
|
274 if(Low == priority ) |
|
275 { |
|
276 RefreshTimestamp(); |
|
277 } |
|
278 if( priority < iPriority ) |
|
279 { |
|
280 User::Leave(KErrAccessDenied); |
|
281 } |
|
282 |
|
283 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap; |
|
284 CleanupStack::PushL(bitmap); |
|
285 User::LeaveIfError(bitmap->Duplicate(bitmapArg.Handle())); |
|
286 CleanupStack::Pop(bitmap); |
|
287 |
|
288 iPriority = priority; |
|
289 delete iThumbnail; |
|
290 iThumbnail = bitmap; |
|
291 RefreshUpdateTimestamp(); |
|
292 |
|
293 iThumbnailProvider->createThumbnail( *iThumbnail, angle); |
|
294 } |
|
295 |
|
296 // -------------------------------------------------------------------------- |
|
297 // CTsFswEntry::RemoveScreenshot |
|
298 // -------------------------------------------------------------------------- |
|
299 // |
|
300 void CTsRunningAppEntry::RemoveScreenshotL() |
|
301 { |
|
302 if (!iThumbnail) { |
|
303 User::Leave(KErrNotFound); |
|
304 } |
|
305 delete iThumbnail; |
|
306 iThumbnail = NULL; |
|
307 iPriority = Low; |
|
308 |
|
309 iObserver.DataChanged(); |
|
310 RefreshUpdateTimestamp(); |
|
311 } |
|
312 |
|
313 // -------------------------------------------------------------------------- |
|
314 /** |
|
315 * Interface implementation |
|
316 * @see MTsThumbnailObserver::ThumbnailCreated( const CFbsBitmap& ) |
|
317 */ |
|
318 void CTsRunningAppEntry::ThumbnailCreated(const CFbsBitmap& aThumbnail) |
|
319 { |
|
320 iThumbnail->Reset(); |
|
321 iThumbnail->Duplicate(aThumbnail.Handle()); |
|
322 RefreshUpdateTimestamp(); |
|
323 iObserver.DataChanged(); |
|
324 } |
|
325 |
|
326 // end of file |