taskswitcher/server/src/tsrunningappmodel.cpp
changeset 116 305818acdca4
child 119 50e220be30d1
equal deleted inserted replaced
112:dbfb5e38438b 116:305818acdca4
       
     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& aResources, 
       
    29                                               MTsWindowGroupsMonitor& aMonitor )
       
    30     {
       
    31     CTsRunningAppModel *self = CTsRunningAppModel::NewLC( aResources, aMonitor );
       
    32     CleanupStack::Pop( self );
       
    33     return self;
       
    34     }
       
    35 
       
    36 CTsRunningAppModel *CTsRunningAppModel::NewLC( MTsResourceManager& aResources, 
       
    37                                                MTsWindowGroupsMonitor& aMonitor )
       
    38     {
       
    39     CTsRunningAppModel *self = new (ELeave) CTsRunningAppModel( aResources );
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL( aResources, aMonitor );
       
    42     return self;
       
    43     }
       
    44 
       
    45 CTsRunningAppModel::~CTsRunningAppModel()
       
    46     {
       
    47     delete iDataList;
       
    48     delete iScreenshotProvider;
       
    49     }
       
    50     
       
    51 CTsRunningAppModel::CTsRunningAppModel( MTsResourceManager& aResources ) 
       
    52 : 
       
    53     iResources( aResources )
       
    54     {
       
    55     }
       
    56 
       
    57 void CTsRunningAppModel::ConstructL( MTsResourceManager& aResources, 
       
    58                                      MTsWindowGroupsMonitor& aMonitor )
       
    59     {
       
    60     iDataList = CTsDataList::NewL( aResources, aMonitor, *this );
       
    61     iScreenshotProvider = CTsScreenshotProvider::NewL( *iDataList );
       
    62 
       
    63     RArray<RWsSession::TWindowGroupChainInfo> wgList;
       
    64     CleanupClosePushL( wgList );
       
    65     User::LeaveIfError( aResources.WsSession().WindowGroupList( 0, &wgList ) );
       
    66     iDataList->HandleWindowGroupChanged( aResources, wgList.Array() );
       
    67     CleanupStack::PopAndDestroy( &wgList );
       
    68     }
       
    69 
       
    70 // --------------------------------------------------------------------------
       
    71 // MHsDataObserver interface implementation
       
    72 // --------------------------------------------------------------------------
       
    73 //
       
    74 void CTsRunningAppModel::DataChanged()
       
    75     {
       
    76     if (iObserver)
       
    77         {
       
    78         iObserver->DataChanged( *this );
       
    79         }
       
    80     }
       
    81 
       
    82 // --------------------------------------------------------------------------
       
    83 // MTsTaskSettings interface implementation
       
    84 // --------------------------------------------------------------------------
       
    85 //
       
    86 TBool CTsRunningAppModel::IsSupported( TInt aFunction ) const
       
    87     {
       
    88     return iDataList->IsSupported( aFunction );
       
    89     }
       
    90 
       
    91 void CTsRunningAppModel::HandleDataL( TInt aFunction, RReadStream& aDataStream )
       
    92     {
       
    93     iDataList->HandleDataL( aFunction, aDataStream );
       
    94     }
       
    95 
       
    96 // --------------------------------------------------------------------------
       
    97 // MTsModel interface implementation
       
    98 // --------------------------------------------------------------------------
       
    99 //
       
   100 TInt CTsRunningAppModel::Count() const
       
   101     {
       
   102     return iDataList->Data().Count();
       
   103     }
       
   104 
       
   105 void CTsRunningAppModel::SetObserver( MTsModelObserver* aObserver )
       
   106     {
       
   107     iObserver = aObserver;
       
   108     }
       
   109 
       
   110 const TDesC& CTsRunningAppModel::DisplayNameL( TInt aOffset ) const
       
   111     {
       
   112     return iDataList->Data()[aOffset]->AppName();
       
   113     }
       
   114 
       
   115 TInt CTsRunningAppModel::IconHandleL( TInt aOffset ) const
       
   116     {
       
   117     CFbsBitmap *bitmap = iDataList->Data()[aOffset]->Screenshot();
       
   118     if( !bitmap )
       
   119         {
       
   120         bitmap = iDataList->Data()[aOffset]->AppIconBitmap();
       
   121         }
       
   122     return bitmap ? bitmap->Handle() : KErrNotFound;
       
   123     }
       
   124 
       
   125 TTime CTsRunningAppModel::TimestampL( TInt aOffset ) const
       
   126     {
       
   127     return iDataList->Data()[aOffset]->Timestamp();
       
   128     }
       
   129 
       
   130 TTime CTsRunningAppModel::TimestampUpdateL(TInt offset) const
       
   131 {
       
   132     return iDataList->Data()[offset]->LastUpdateTimestamp();
       
   133 }
       
   134 
       
   135 TTsModelItemKey CTsRunningAppModel::KeyL( TInt aOffset ) const
       
   136     {
       
   137     return TTsModelItemKey(iDataList->Data()[aOffset]->Key().WindowGroupId(), 
       
   138                            reinterpret_cast<TInt>(this));
       
   139     }
       
   140 
       
   141 TBool CTsRunningAppModel::IsActiveL( TInt /*aOffset*/ ) const
       
   142     {
       
   143     return ETrue;
       
   144     }
       
   145 
       
   146 TBool CTsRunningAppModel::IsClosableL( TInt aOffset ) const
       
   147     {
       
   148     return iDataList->Data()[aOffset]->CloseableApp();
       
   149     }
       
   150 
       
   151 TBool CTsRunningAppModel::CloseL( TTsModelItemKey aKey ) const
       
   152     {
       
   153     TApaTask task( iResources.WsSession() );
       
   154     task.SetWgId( aKey.Key() );
       
   155     task.EndTask();
       
   156     return ETrue;
       
   157     }
       
   158 
       
   159 TBool CTsRunningAppModel::LaunchL( TTsModelItemKey aKey ) const 
       
   160     {
       
   161     // find uid by wgid from key
       
   162     CApaWindowGroupName *windowGroupName = 
       
   163         CApaWindowGroupName::NewLC( iResources.WsSession(), aKey.Key() );
       
   164     TUid uid = windowGroupName->AppUid();
       
   165     CleanupStack::PopAndDestroy( windowGroupName );
       
   166 
       
   167     TApaTask task = TApaTaskList( iResources.WsSession() ).FindApp( uid );
       
   168     task.BringToForeground();
       
   169     return task.Exists();
       
   170     }