--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/taskswitcher/server/src/tsrunningappmodel.cpp Thu Sep 16 12:11:40 2010 +0100
@@ -0,0 +1,163 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+#include "tsrunningappmodel.h"
+
+#include <AknDef.h>
+#include <apgwgnam.h>
+#include <apgtask.h>
+
+#include "tsdatalist.h"
+#include "tsmodelobserver.h"
+#include "tsscreenshotprovider.h"
+
+CTsRunningAppModel *CTsRunningAppModel::NewL(MTsResourceManager &resources, MTsWindowGroupsMonitor &monitor)
+{
+ CTsRunningAppModel *self = CTsRunningAppModel::NewLC(resources, monitor);
+ CleanupStack::Pop(self);
+ return self;
+}
+
+CTsRunningAppModel *CTsRunningAppModel::NewLC(MTsResourceManager &resources, MTsWindowGroupsMonitor &monitor)
+{
+ CTsRunningAppModel *self = new (ELeave) CTsRunningAppModel(resources);
+ CleanupStack::PushL(self);
+ self->ConstructL(resources, monitor);
+ return self;
+}
+
+CTsRunningAppModel::~CTsRunningAppModel()
+{
+ delete mDataList;
+ delete mScreenshotProvider;
+}
+
+CTsRunningAppModel::CTsRunningAppModel(MTsResourceManager &resources) : mResources(resources)
+{
+}
+
+void CTsRunningAppModel::ConstructL(MTsResourceManager &resources, MTsWindowGroupsMonitor &monitor)
+{
+ mDataList = CTsDataList::NewL(resources, monitor, *this);
+ mScreenshotProvider = CTsScreenshotProvider::NewL(*mDataList);
+
+ RArray<RWsSession::TWindowGroupChainInfo> wgList;
+ CleanupClosePushL(wgList);
+ User::LeaveIfError(resources.WsSession().WindowGroupList(0, &wgList));
+ mDataList->HandleWindowGroupChanged(resources, wgList.Array());
+ CleanupStack::PopAndDestroy(&wgList);
+}
+
+// --------------------------------------------------------------------------
+// MHsDataObserver interface implementation
+// --------------------------------------------------------------------------
+//
+void CTsRunningAppModel::DataChanged()
+{
+ if (mObserver) {
+ mObserver->dataChanged(*this);
+ }
+}
+
+// --------------------------------------------------------------------------
+// MTsTaskSettings interface implementation
+// --------------------------------------------------------------------------
+//
+TBool CTsRunningAppModel::isSupported(TInt function) const
+{
+ return mDataList->isSupported(function);
+}
+
+void CTsRunningAppModel::handleDataL(TInt function,RReadStream& dataStream)
+{
+ mDataList->handleDataL(function, dataStream);
+}
+
+// --------------------------------------------------------------------------
+// MTsModel interface implementation
+// --------------------------------------------------------------------------
+//
+TInt CTsRunningAppModel::count() const
+{
+ return mDataList->Data().Count();
+}
+
+void CTsRunningAppModel::setObserver(MTsModelObserver *observer)
+{
+ mObserver = observer;
+}
+
+const TDesC& CTsRunningAppModel::displayNameL(TInt offset) const
+{
+ return mDataList->Data()[offset]->AppName();
+}
+
+TInt CTsRunningAppModel::iconHandleL(TInt offset) const
+{
+ CFbsBitmap *bitmap = mDataList->Data()[offset]->Screenshot();
+ if (!bitmap) {
+ bitmap = mDataList->Data()[offset]->AppIconBitmap();
+ }
+
+ if (bitmap) {
+ return bitmap->Handle();
+ } else {
+ return KErrNotFound;
+ }
+}
+
+TTime CTsRunningAppModel::timestampL(TInt offset) const
+{
+ return mDataList->Data()[offset]->Timestamp();
+}
+
+TTsModelItemKey CTsRunningAppModel::keyL(TInt offset) const
+{
+ return TTsModelItemKey(mDataList->Data()[offset]->Key().WindowGroupId(),
+ reinterpret_cast<TInt>(this));
+}
+
+TBool CTsRunningAppModel::isActiveL(TInt /*offset*/) const
+{
+ return ETrue;
+}
+
+TBool CTsRunningAppModel::isClosableL(TInt offset) const
+{
+ return mDataList->Data()[offset]->CloseableApp();
+}
+
+TBool CTsRunningAppModel::closeL(TTsModelItemKey key) const
+{
+ TApaTask task(mResources.WsSession());
+ task.SetWgId(key.key());
+ task.EndTask();
+ return ETrue;
+}
+
+TBool CTsRunningAppModel::launchL(TTsModelItemKey key) const
+{
+ // find uid by wgid from key
+ CApaWindowGroupName *windowGroupName =
+ CApaWindowGroupName::NewLC(mResources.WsSession(), key.key());
+ TUid uid = windowGroupName->AppUid();
+ CleanupStack::PopAndDestroy(windowGroupName);
+
+ TApaTask task = TApaTaskList(mResources.WsSession()).FindApp(uid);
+ task.BringToForeground();
+ return task.Exists();
+}