tstaskmonitor/utils/src/tsfswentry.cpp
changeset 104 9b022b1f357c
parent 103 b99b84bcd2d1
child 105 e7325f632549
child 109 e0aa398e6810
equal deleted inserted replaced
103:b99b84bcd2d1 104:9b022b1f357c
     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 #define __E32SVR_H__
       
    19 #include "tsfswentry.h"
       
    20 #include "tsdataobserver.h"
       
    21 #include <s32strm.h>
       
    22 #include <fbs.h>
       
    23 
       
    24 // --------------------------------------------------------------------------
       
    25 // CTsFswEntry::NewL
       
    26 // --------------------------------------------------------------------------
       
    27 //
       
    28 CTsFswEntry* CTsFswEntry::NewL()
       
    29 {
       
    30     CTsFswEntry* self = NewLC();
       
    31     CleanupStack::Pop(self);
       
    32     return self;
       
    33 }
       
    34 
       
    35 // --------------------------------------------------------------------------
       
    36 // CTsFswEntry::NewLC
       
    37 // --------------------------------------------------------------------------
       
    38 //
       
    39 CTsFswEntry* CTsFswEntry::NewLC()
       
    40 {
       
    41     CTsFswEntry* self = new (ELeave) CTsFswEntry;
       
    42     CleanupStack::PushL(self);
       
    43     return self;
       
    44 }
       
    45 
       
    46 // --------------------------------------------------------------------------
       
    47 // CTsFswEntry::NewL
       
    48 // --------------------------------------------------------------------------
       
    49 //
       
    50 CTsFswEntry* CTsFswEntry::NewL(const TTsEntryKey& key, MHsDataObserver *observer)
       
    51 {
       
    52     CTsFswEntry* self = NewLC(key, observer);
       
    53     CleanupStack::Pop(self);
       
    54     return self;
       
    55 }
       
    56 
       
    57 // --------------------------------------------------------------------------
       
    58 // CTsFswEntry::NewLC
       
    59 // --------------------------------------------------------------------------
       
    60 //
       
    61 CTsFswEntry* CTsFswEntry::NewLC(const TTsEntryKey& key, MHsDataObserver* observer)
       
    62 {
       
    63     CTsFswEntry* self = new (ELeave) CTsFswEntry(key, observer);
       
    64     CleanupStack::PushL(self);
       
    65     return self;
       
    66 }
       
    67 
       
    68 // --------------------------------------------------------------------------
       
    69 // CTsFswEntry::~CTsFswEntry
       
    70 // --------------------------------------------------------------------------
       
    71 //
       
    72 CTsFswEntry::~CTsFswEntry()
       
    73 {
       
    74     delete mAppName;
       
    75     delete mAppIconBitmap;
       
    76     delete mAppIconMask;
       
    77     delete mScreenshot;
       
    78     delete mImgTool;
       
    79 }
       
    80 
       
    81 // --------------------------------------------------------------------------
       
    82 // CTsFswEntry::CTsFswEntry
       
    83 // --------------------------------------------------------------------------
       
    84 //
       
    85 CTsFswEntry::CTsFswEntry() :
       
    86     mPriority(Low)
       
    87 {
       
    88     mKey = TTsEntryKey();
       
    89 }
       
    90 
       
    91 // --------------------------------------------------------------------------
       
    92 // CTsFswEntry::CTsFswEntry
       
    93 // --------------------------------------------------------------------------
       
    94 //
       
    95 CTsFswEntry::CTsFswEntry(const TTsEntryKey& key, MHsDataObserver *observer) :
       
    96     mKey(key), mPriority(Low), mObserver(observer)
       
    97 {
       
    98     mWgId = key.mParentId;
       
    99 }
       
   100 
       
   101 // --------------------------------------------------------------------------
       
   102 // CTsFswEntry::SetWgId
       
   103 // --------------------------------------------------------------------------
       
   104 //
       
   105 void CTsFswEntry::SetWgId(TInt wgId)
       
   106 {
       
   107     mWgId = wgId;
       
   108     mKey = TTsEntryKey(mWgId);
       
   109 }
       
   110 
       
   111 // --------------------------------------------------------------------------
       
   112 // CTsFswEntry::SetAppUid
       
   113 // --------------------------------------------------------------------------
       
   114 //
       
   115 void CTsFswEntry::SetAppUid(const TUid& uid)
       
   116 {
       
   117     mAppUid = uid;
       
   118 }
       
   119 
       
   120 // --------------------------------------------------------------------------
       
   121 // CTsFswEntry::SetAppNameL
       
   122 // --------------------------------------------------------------------------
       
   123 //
       
   124 void CTsFswEntry::SetAppNameL(const TDesC& appName)
       
   125 {
       
   126     delete mAppName;
       
   127     mAppName = 0;
       
   128     mAppName = appName.AllocL();
       
   129 }
       
   130 
       
   131 // --------------------------------------------------------------------------
       
   132 // CTsFswEntry::SetSystemApp
       
   133 // --------------------------------------------------------------------------
       
   134 //
       
   135 void CTsFswEntry::SetCloseableApp(TBool value)
       
   136 {
       
   137     mCloseableApp = value;
       
   138 }
       
   139 
       
   140 // --------------------------------------------------------------------------
       
   141 // CTsFswEntry::SetAppIconHandles
       
   142 // --------------------------------------------------------------------------
       
   143 //
       
   144 void CTsFswEntry::SetAppIcon(CFbsBitmap* bitmap, CFbsBitmap* mask)
       
   145 {
       
   146     mAppIconBitmap = bitmap;
       
   147     mAppIconMask = mask;
       
   148 }
       
   149 
       
   150 // --------------------------------------------------------------------------
       
   151 // CTsFswEntry::WgId
       
   152 // --------------------------------------------------------------------------
       
   153 //
       
   154 TInt CTsFswEntry::WgId() const
       
   155 {
       
   156     return mWgId;
       
   157 }
       
   158 
       
   159 // --------------------------------------------------------------------------
       
   160 // CTsFswEntry::AppUid
       
   161 // --------------------------------------------------------------------------
       
   162 //
       
   163 TUid CTsFswEntry::AppUid() const
       
   164 {
       
   165     return mAppUid;
       
   166 }
       
   167 
       
   168 // --------------------------------------------------------------------------
       
   169 // CTsFswEntry::AppName
       
   170 // --------------------------------------------------------------------------
       
   171 //
       
   172 const TDesC& CTsFswEntry::AppName() const
       
   173 {
       
   174     return mAppName ? *mAppName : KNullDesC();
       
   175 }
       
   176 
       
   177 // --------------------------------------------------------------------------
       
   178 // CTsFswEntry::SystemApp
       
   179 // --------------------------------------------------------------------------
       
   180 //
       
   181 TBool CTsFswEntry::CloseableApp() const
       
   182 {
       
   183     return mCloseableApp;
       
   184 }
       
   185 
       
   186 // --------------------------------------------------------------------------
       
   187 // CTsFswEntry::AppIconBitmapHandle
       
   188 // --------------------------------------------------------------------------
       
   189 //
       
   190 CFbsBitmap* CTsFswEntry::AppIconBitmap() const
       
   191 {
       
   192     return mAppIconBitmap;
       
   193 }
       
   194 
       
   195 // --------------------------------------------------------------------------
       
   196 // CTsFswEntry::AppIconMaskHandle
       
   197 // --------------------------------------------------------------------------
       
   198 //
       
   199 CFbsBitmap* CTsFswEntry::AppIconMask() const
       
   200 {
       
   201     return mAppIconMask;
       
   202 }
       
   203 
       
   204 // --------------------------------------------------------------------------
       
   205 // CTsFswEntry::Key
       
   206 // --------------------------------------------------------------------------
       
   207 //
       
   208 const TTsEntryKey& CTsFswEntry::Key() const
       
   209 {
       
   210     return mKey;
       
   211 }
       
   212 // --------------------------------------------------------------------------
       
   213 // CTsFswEntry::ExternalizeL
       
   214 // --------------------------------------------------------------------------
       
   215 //
       
   216 void CTsFswEntry::ExternalizeL(RWriteStream& stream)
       
   217 {
       
   218     stream.WriteInt32L(mWgId);
       
   219     stream.WriteInt32L(mAppUid.iUid);
       
   220     stream << AppName();
       
   221     stream.WriteInt32L(mCloseableApp);
       
   222     if (mAppIconBitmap) {
       
   223         stream.WriteInt32L(mAppIconBitmap->Handle());
       
   224     }
       
   225     else {
       
   226         stream.WriteInt32L(KErrNotFound);
       
   227     }
       
   228 
       
   229     if (mAppIconMask) {
       
   230         stream.WriteInt32L(mAppIconMask->Handle());
       
   231     }
       
   232     else {
       
   233         stream.WriteInt32L(KErrNotFound);
       
   234     }
       
   235 
       
   236     if (mScreenshot) {
       
   237         stream.WriteInt32L(mScreenshot->Handle());
       
   238     }
       
   239     else {
       
   240         stream.WriteInt32L(KErrNotFound);
       
   241     }
       
   242 
       
   243     mKey.ExternalizeL(stream);
       
   244     TInt currentPriority = static_cast<TInt> (mPriority);
       
   245     stream.WriteInt32L(currentPriority);
       
   246 }
       
   247 
       
   248 // --------------------------------------------------------------------------
       
   249 // CTsFswEntry::InternalizeL
       
   250 // --------------------------------------------------------------------------
       
   251 //
       
   252 void CTsFswEntry::InternalizeL(RReadStream& stream)
       
   253 {
       
   254     mWgId = stream.ReadInt32L();
       
   255     mAppUid = TUid::Uid(stream.ReadInt32L());
       
   256     delete mAppName;
       
   257     mAppName = NULL;
       
   258     mAppName = HBufC::NewL(stream, KMaxTInt);
       
   259     mCloseableApp = stream.ReadInt32L();
       
   260     TInt appIconBitmapHandle = stream.ReadInt32L();
       
   261     TInt appIconMaskHandle = stream.ReadInt32L();
       
   262     TInt screenshotHandle = stream.ReadInt32L();
       
   263     if (appIconBitmapHandle != KErrNotFound) {
       
   264         mAppIconBitmap = new (ELeave) CFbsBitmap;
       
   265         mAppIconBitmap->Duplicate(appIconBitmapHandle);
       
   266     }
       
   267     if (appIconMaskHandle != KErrNotFound) {
       
   268         mAppIconMask = new (ELeave) CFbsBitmap;
       
   269         mAppIconMask->Duplicate(appIconMaskHandle);
       
   270     }
       
   271     if (screenshotHandle != KErrNotFound) {
       
   272         mScreenshot = new (ELeave) CFbsBitmap;
       
   273         mScreenshot->Duplicate(screenshotHandle);
       
   274     }
       
   275     mKey.InternalizeL(stream);
       
   276     TInt currentPriority = stream.ReadInt32L();
       
   277     mPriority = static_cast<UpdatePriority> (currentPriority);
       
   278 }
       
   279 
       
   280 // --------------------------------------------------------------------------
       
   281 // CTsFswEntry::ExternalizeArrayL
       
   282 // --------------------------------------------------------------------------
       
   283 //
       
   284 void CTsFswEntry::ExternalizeArrayL(RWriteStream& stream, const RTsFswArray& aArray)
       
   285 {
       
   286     TInt count = aArray.Count();
       
   287     stream.WriteInt32L(count);
       
   288     for (TInt i = 0; i < count; ++i) {
       
   289         aArray[i]->ExternalizeL(stream);
       
   290     }
       
   291 }
       
   292 
       
   293 // --------------------------------------------------------------------------
       
   294 // CTsFswEntry::InternalizeArrayL
       
   295 // --------------------------------------------------------------------------
       
   296 //
       
   297 void CTsFswEntry::InternalizeArrayL(RReadStream& stream, RTsFswArray& aArray)
       
   298 {
       
   299     aArray.ResetAndDestroy();
       
   300     TInt count = stream.ReadInt32L();
       
   301     for (TInt i = 0; i < count; ++i) {
       
   302         CTsFswEntry* entry = CTsFswEntry::NewLC();
       
   303         entry->InternalizeL(stream);
       
   304         aArray.AppendL(entry);
       
   305         CleanupStack::Pop(entry);
       
   306     }
       
   307 }
       
   308 
       
   309 // --------------------------------------------------------------------------
       
   310 // CTsFswEntry::Type
       
   311 // --------------------------------------------------------------------------
       
   312 //
       
   313 TAppType CTsFswEntry::Type() const
       
   314 {
       
   315     return EApp;
       
   316 }
       
   317 
       
   318 // --------------------------------------------------------------------------
       
   319 // CTsFswEntry::SetScreenshot
       
   320 // --------------------------------------------------------------------------
       
   321 //
       
   322 void CTsFswEntry::SetScreenshotL(const CFbsBitmap* bitmapArg, UpdatePriority priority)
       
   323 {
       
   324     TInt currentPriority = static_cast<TInt> (mPriority);
       
   325     TInt newPriority = static_cast<TInt> (priority);
       
   326     if(newPriority <currentPriority) {
       
   327         User::Leave(KErrAccessDenied);
       
   328     }
       
   329     
       
   330     CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
   331     CleanupStack::PushL(bitmap);
       
   332     User::LeaveIfError(bitmap->Duplicate(bitmapArg->Handle()));
       
   333     CleanupStack::Pop(bitmap);
       
   334 
       
   335     mPriority = priority;
       
   336     delete mScreenshot;
       
   337     mScreenshot = bitmap;
       
   338 
       
   339     delete mImgTool;
       
   340     mImgTool = 0;
       
   341 
       
   342     mImgTool = CTsGraphicFileScalingHandler::NewL(*this, *mScreenshot, TSize(128, 128),
       
   343     CTsGraphicFileScalingHandler::EKeepAspectRatioByExpanding);
       
   344 }
       
   345 
       
   346 // --------------------------------------------------------------------------
       
   347 // CTsFswEntry::RemoveScreenshot
       
   348 // --------------------------------------------------------------------------
       
   349 //
       
   350 void CTsFswEntry::RemoveScreenshotL()
       
   351 {
       
   352     if (!mScreenshot) {
       
   353         User::Leave(KErrNotFound);
       
   354     }
       
   355     delete mScreenshot;
       
   356     mScreenshot = NULL;
       
   357     mPriority = Low;
       
   358     if (mObserver) {
       
   359         mObserver->DataChanged();
       
   360     }
       
   361 }
       
   362 
       
   363 // --------------------------------------------------------------------------
       
   364 // CTsFswEntry::Screenshot
       
   365 // --------------------------------------------------------------------------
       
   366 //
       
   367 CFbsBitmap* CTsFswEntry::Screenshot() const
       
   368 {
       
   369     return mScreenshot;
       
   370 }
       
   371 
       
   372 // --------------------------------------------------------------------------
       
   373 // CTsFswEntry::Priority
       
   374 // --------------------------------------------------------------------------
       
   375 //
       
   376 UpdatePriority CTsFswEntry::Priority() const
       
   377 {
       
   378     return mPriority;
       
   379 }
       
   380 
       
   381 // --------------------------------------------------------------------------
       
   382 // CTsFswEntry::Priority
       
   383 // --------------------------------------------------------------------------
       
   384 //
       
   385 void CTsFswEntry::ImageReadyCallBack(TInt error, const CFbsBitmap *bitmap)
       
   386 {
       
   387     if (KErrNone == error && 0 != bitmap) {
       
   388         mScreenshot->Reset();
       
   389         mScreenshot->Duplicate(bitmap->Handle());
       
   390 
       
   391         if (mObserver) {
       
   392             mObserver->DataChanged();
       
   393         }
       
   394     }
       
   395 }
       
   396 
       
   397 // end of file