taskswitcher/server/src/tsmodelitem.cpp
changeset 121 0b3699f6c654
child 119 50e220be30d1
equal deleted inserted replaced
115:3ab5c078b490 121:0b3699f6c654
       
     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 #include "tsmodel.h"
       
    18 // -----------------------------------------------------------------------------
       
    19 /**
       
    20  * Constructor
       
    21  * @param aModel - data owner
       
    22  * @param aOffset - data index
       
    23  */
       
    24 TTsModelItem::TTsModelItem( const MTsModel& aModel, TInt aOffset )
       
    25 :
       
    26 iModel( aModel ),
       
    27 iIndex( aOffset )
       
    28 
       
    29     {
       
    30     //No implementation required
       
    31     }
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 /**
       
    35  * Copy constructor
       
    36  * @param aItem - template item
       
    37  */
       
    38 TTsModelItem::TTsModelItem( const TTsModelItem& aItem )
       
    39 :
       
    40 iModel( aItem.iModel ),
       
    41 iIndex( aItem.iIndex )
       
    42     {
       
    43     //No implementation required
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 /**
       
    48  * Validate item instance and retrieve display name data
       
    49  * @return item display name
       
    50  */
       
    51 const TDesC& TTsModelItem::DisplayNameL() const
       
    52     {
       
    53     ValidateL();
       
    54     return iModel.DisplayNameL( iIndex );
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 /**
       
    59  * Validate item instance and retrieve icon handle ( CFbsBitmap handle )
       
    60  * @return item icon handle
       
    61  */
       
    62 TInt TTsModelItem::IconHandleL() const
       
    63     {
       
    64     ValidateL();
       
    65     return iModel.IconHandleL( iIndex );
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 /**
       
    70  * Validate item instance and retrieve entry key
       
    71  * @return item key
       
    72  */
       
    73 TTsModelItemKey TTsModelItem::KeyL() const
       
    74     {
       
    75     ValidateL();
       
    76     return iModel.KeyL( iIndex );
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 /**
       
    81  * Validate item instance and retrieve entry timestamp
       
    82  * @return item timestamp
       
    83  */
       
    84 TTime TTsModelItem::TimestampL() const
       
    85     {
       
    86     ValidateL();
       
    87     return iModel.TimestampL( iIndex );
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 /**
       
    92  * Validate item instance and retrieve timestamp
       
    93  * with latest update time
       
    94  * @return item timestamp
       
    95  */
       
    96 TTime TTsModelItem::TimestampUpdateL() const 
       
    97 {
       
    98     ValidateL();
       
    99     return iModel.TimestampUpdateL(iIndex);
       
   100 }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 /**
       
   104  * Validate item instance and retrieve activity status 
       
   105  * @return activity status
       
   106  */
       
   107 TBool TTsModelItem::IsActiveL() const
       
   108     {
       
   109     ValidateL();
       
   110     return iModel.IsActiveL( iIndex );
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 /**
       
   115  * Validate item instance and retrieve closable status 
       
   116  * @return closable status
       
   117  */
       
   118 TBool TTsModelItem::IsClosableL() const
       
   119     {
       
   120     ValidateL();
       
   121     return iModel.IsClosableL( iIndex );
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 /**
       
   126  * Validate item instance and forward close request to its owner 
       
   127  * @return EFalse on failure
       
   128  */
       
   129 TBool TTsModelItem::CloseL() const
       
   130     {
       
   131     ValidateL();
       
   132     return iModel.CloseL( KeyL() );
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 /**
       
   137  * Validate item instance and forward launch request to its owner 
       
   138  * @return EFalse on failure
       
   139  */
       
   140 TBool TTsModelItem::LaunchL() const
       
   141     {
       
   142     ValidateL();
       
   143     return iModel.LaunchL( KeyL() );
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 /**
       
   148  * Validate item instance 
       
   149  */
       
   150 void TTsModelItem::ValidateL() const
       
   151     {
       
   152     if(iModel.Count() <= iIndex )
       
   153         {
       
   154         User::Leave( KErrOverflow );
       
   155         }
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 /**
       
   160  * Serialize item into destination stream
       
   161  * @param aStream - output stream 
       
   162  */
       
   163 
       
   164 void TTsModelItem::ExternalizeL( RWriteStream& aStream ) const
       
   165     {
       
   166     aStream.WriteInt32L( DisplayNameL().Length() );
       
   167     if( 0 < DisplayNameL().Length() )
       
   168         {
       
   169         aStream << DisplayNameL();
       
   170         }
       
   171     TPckgBuf<TTime> timestamp(TimestampUpdateL()); 
       
   172     aStream.WriteL(timestamp);
       
   173     aStream.WriteInt32L( IconHandleL() );
       
   174     aStream.WriteInt32L( TTsModelItemKey::Size() );
       
   175     aStream << KeyL();
       
   176     aStream.WriteInt32L( IsActiveL() );
       
   177     aStream.WriteInt32L( IsClosableL() );
       
   178     }
       
   179