taskswitcher/server/src/tsmodelitem.cpp
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     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 model - data owner
       
    22  * @param offset - data index
       
    23  */
       
    24 TTsModelItem::TTsModelItem(const MTsModel& model, TInt offset)
       
    25 :
       
    26 mModel(model),
       
    27 mIndex(offset)
       
    28 {}
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 /**
       
    32  * Copy constructor
       
    33  * @param item - template item
       
    34  */
       
    35 TTsModelItem::TTsModelItem(const TTsModelItem& item)
       
    36 :
       
    37 mModel(item.mModel),
       
    38 mIndex(item.mIndex)
       
    39 {}
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 /**
       
    43  * Validate item instance and retrieve display name data
       
    44  * @return item display name
       
    45  */
       
    46 const TDesC& TTsModelItem::displayNameL() const
       
    47 {
       
    48     validateL();
       
    49     return mModel.displayNameL(mIndex);
       
    50 }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 /**
       
    54  * Validate item instance and retrieve icon handle ( CFbsBitmap handle )
       
    55  * @return item icon handle
       
    56  */
       
    57 TInt TTsModelItem::iconHandleL() const
       
    58 {
       
    59     validateL();
       
    60     return mModel.iconHandleL(mIndex);
       
    61 }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 /**
       
    65  * Validate item instance and retrieve entry key
       
    66  * @return item key
       
    67  */
       
    68 TTsModelItemKey TTsModelItem::keyL() const
       
    69 {
       
    70     validateL();
       
    71     return mModel.keyL(mIndex);
       
    72 }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 /**
       
    76  * Validate item instance and retrieve entry timestamp
       
    77  * @return item timestamp
       
    78  */
       
    79 TTime TTsModelItem::timestampL() const
       
    80 {
       
    81     validateL();
       
    82     return mModel.timestampL(mIndex);
       
    83 }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 /**
       
    87  * Validate item instance and retrieve activity status 
       
    88  * @return activity status
       
    89  */
       
    90 TBool TTsModelItem::isActiveL() const
       
    91 {
       
    92     validateL();
       
    93     return mModel.isActiveL(mIndex);
       
    94 }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 /**
       
    98  * Validate item instance and retrieve closable status 
       
    99  * @return closable status
       
   100  */
       
   101 TBool TTsModelItem::isClosableL() const
       
   102 {
       
   103     validateL();
       
   104     return mModel.isClosableL(mIndex);
       
   105 }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 /**
       
   109  * Validate item instance and forward close request to its owner 
       
   110  * @return EFalse on failure
       
   111  */
       
   112 TBool TTsModelItem::closeL() const
       
   113 {
       
   114     validateL();
       
   115     return mModel.closeL(keyL());
       
   116 }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 /**
       
   120  * Validate item instance and forward launch request to its owner 
       
   121  * @return EFalse on failure
       
   122  */
       
   123 TBool TTsModelItem::launchL() const
       
   124 {
       
   125     validateL();
       
   126     return mModel.launchL(keyL());
       
   127 }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 /**
       
   131  * Validate item instance 
       
   132  */
       
   133 void TTsModelItem::validateL() const
       
   134 {
       
   135     if (mModel.count() <= mIndex) {
       
   136         User::Leave(KErrOverflow);
       
   137     }
       
   138 }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 /**
       
   142  * Serialize item into destination stream
       
   143  * @param stream - output stream 
       
   144  */
       
   145 
       
   146 void TTsModelItem::ExternalizeL(RWriteStream& stream) const
       
   147 {
       
   148     stream.WriteInt32L(displayNameL().Length());
       
   149     if (0 < displayNameL().Length()) {
       
   150         stream << displayNameL();
       
   151     }
       
   152     stream.WriteInt32L(iconHandleL());
       
   153     stream.WriteInt32L(TTsModelItemKey::size());
       
   154     stream << keyL();
       
   155     stream.WriteInt32L(isActiveL());
       
   156     stream.WriteInt32L(isClosableL());
       
   157 }