activityfw/storage/client/src/afstorageclient_p.cpp
changeset 107 b34d53f6acdf
child 116 305818acdca4
equal deleted inserted replaced
106:e78d6e055a5b 107:b34d53f6acdf
       
     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 "afstorageclient_p.h"
       
    18 
       
    19 #include <fbs.h>
       
    20 #include <s32mem.h>
       
    21 
       
    22 #include "afasyncrequest_p.h"
       
    23 #include "afstorageglobals.h"
       
    24 #include "afentry.h"
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 /**
       
    28  * Two-phase constructor. Create and initialize instance
       
    29  * @return entry instance
       
    30  */
       
    31 CAfStorageClientPrivate *CAfStorageClientPrivate::NewL(MAfAsyncRequestObserver &observer)
       
    32 {
       
    33     CAfStorageClientPrivate *self = CAfStorageClientPrivate::NewLC(observer);
       
    34     CleanupStack::Pop(self);
       
    35     return self;
       
    36 }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 /**
       
    40  * Two-phase constructor. Create, initialize and push instance into cleanup stack
       
    41  * @return entry instance
       
    42  */
       
    43 CAfStorageClientPrivate *CAfStorageClientPrivate::NewLC(MAfAsyncRequestObserver &observer)
       
    44 {
       
    45     CAfStorageClientPrivate *self = new (ELeave) CAfStorageClientPrivate(observer);
       
    46     CleanupStack::PushL(self);
       
    47     self->ConstructL();
       
    48     return self;
       
    49 }    
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 /**
       
    53  * Destructor
       
    54  */
       
    55 CAfStorageClientPrivate::~CAfStorageClientPrivate()
       
    56 {
       
    57     mImplementation.Close();
       
    58 }
       
    59     
       
    60 // -----------------------------------------------------------------------------
       
    61 /**
       
    62  * Constructor
       
    63  */
       
    64 CAfStorageClientPrivate::CAfStorageClientPrivate(MAfAsyncRequestObserver &observer) : mImplementation(observer)
       
    65 {
       
    66 }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 /**
       
    70  * 2nd phase of construction
       
    71  */
       
    72 void CAfStorageClientPrivate::ConstructL()
       
    73 {
       
    74     mImplementation.connectL();
       
    75 }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 /**
       
    79  * Function implementation
       
    80  * @see AfStorageClient::addActivity(const CAfEntry &,const QPixmap&)
       
    81  */
       
    82 int CAfStorageClientPrivate::addActivity(const CAfEntry &entry, TInt imageHandle)
       
    83 {
       
    84     return execute(AddActivity, entry, imageHandle);
       
    85 }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 /**
       
    89  * Function implementation
       
    90  * @see AfStorageClient::updateActivity(const CAfEntry &,const QPixmap&)
       
    91  */
       
    92 int CAfStorageClientPrivate::updateActivity(const CAfEntry &entry, TInt imageHandle)
       
    93 {
       
    94     return execute(UpdateActivity, entry, imageHandle);
       
    95 }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 /**
       
    99  * Function implementation
       
   100  * @see AfStorageClient::saveActivity(const CAfEntry &,const QPixmap&)
       
   101  */
       
   102 int CAfStorageClientPrivate::saveActivity(const CAfEntry &entry, TInt imageHandle)
       
   103 {
       
   104     return execute(SaveActivity, entry, imageHandle);
       
   105 }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 /**
       
   109  * Function implementation
       
   110  * @see AfStorageClient::removeActivity(const CAfEntry &)
       
   111  */
       
   112 int CAfStorageClientPrivate::removeActivity(const CAfEntry &entry)
       
   113 {
       
   114     return execute(RemoveActivity, entry, -1);
       
   115 }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 /**
       
   119  * Function implementation
       
   120  * @see AfStorageClient::removeApplicationActivities(const CAfEntry &)
       
   121  */
       
   122 int CAfStorageClientPrivate::removeApplicationActivities(const CAfEntry &entry)
       
   123 {
       
   124     return execute(RemoveApplicationActivities, entry, -1);
       
   125 }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 /**
       
   129  * Function implementation
       
   130  * @see AfStorageClient::activities(RPointerArray<CAfEntry> &)
       
   131  */
       
   132 int CAfStorageClientPrivate::activities(RPointerArray<CAfEntry> &results)
       
   133 {
       
   134     CAfEntry *entry = CAfEntry::NewL();
       
   135     TInt result = execute(Activities, results, *entry);
       
   136     delete entry;
       
   137     return result;
       
   138 }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 /**
       
   142  * Function implementation
       
   143  * @see AfStorageClient::applicationActivities(RPointerArray<CAfEntry> &, const CAfEntry &)
       
   144  */
       
   145 int CAfStorageClientPrivate::applicationActivities(RPointerArray<CAfEntry> &results, const CAfEntry &templateEntry)
       
   146 {
       
   147     return execute(ApplicationActivities, results, templateEntry);
       
   148 }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 /**
       
   152  * Function implementation
       
   153  * @see AfStorageClient::activityData(CAfEntry &, const CAfEntry &)
       
   154  */
       
   155 int CAfStorageClientPrivate::activityData(CAfEntry *&resultEntry, const CAfEntry &templateEntry)
       
   156 {   
       
   157     RPointerArray<CAfEntry> results;
       
   158     int errNo(execute(ApplicationActivity, results, templateEntry));
       
   159     if (KErrNone == errNo && results.Count() > 0) {
       
   160         resultEntry = results[0];
       
   161         results.Remove(0);
       
   162     }
       
   163     results.ResetAndDestroy();
       
   164     return errNo;
       
   165 }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 /**
       
   169  * Function implementation
       
   170  * @see AfStorageClient::waitActivity()
       
   171  */
       
   172 int CAfStorageClientPrivate::waitActivity()
       
   173 {
       
   174     CAfEntry *entry = CAfEntry::NewL();
       
   175     TInt result = execute(WaitActivity, *entry, -1);
       
   176     delete entry;
       
   177     return result;
       
   178 }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 /**
       
   182  * Function implementation
       
   183  * @see AfStorageClient::getThumbnail(const TSize &size, const TDesC &imagePath, void *userData)
       
   184  */
       
   185 int CAfStorageClientPrivate::getThumbnail(const TSize &size, const TDesC &imagePath, void *userData)
       
   186 {
       
   187     TRAPD(errNo, mImplementation.getThumbnailL(size, imagePath, userData);)
       
   188     return errNo;
       
   189 }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 /**
       
   193  * Function implementation
       
   194  * @see AfStorageClient::notifyDataChange()
       
   195  */
       
   196 int CAfStorageClientPrivate::notifyDataChange()
       
   197 {
       
   198     CAfEntry *entry = CAfEntry::NewL();
       
   199     TInt result = execute(NotifyChange, *entry, -1);
       
   200     delete entry;
       
   201     return result;
       
   202 }
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 /**
       
   206  * Function implementation
       
   207  * @see AfStorageClient::launchActivity(const CAfEntry &)
       
   208  */
       
   209 int CAfStorageClientPrivate::launchActivity(const CAfEntry &templateEntry)
       
   210 {
       
   211     return execute(LaunchActivity, templateEntry, -1);
       
   212 }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 /**
       
   216  * Function execute activity framework functinality and return results 
       
   217  */
       
   218 int CAfStorageClientPrivate::execute(int function, const CAfEntry &sourceEntry, TInt imageHandle)
       
   219 {
       
   220     TRAPD(errNo,
       
   221         switch (function) {
       
   222         case AddActivity:
       
   223         case UpdateActivity:
       
   224         case SaveActivity:
       
   225         case RemoveActivity:
       
   226         case RemoveApplicationActivities:
       
   227         case LaunchActivity:
       
   228             mImplementation.executeL(function, sourceEntry, imageHandle);
       
   229             break;
       
   230         
       
   231         case WaitActivity:
       
   232         case NotifyChange:
       
   233             mImplementation.executeL(function);
       
   234             break;
       
   235         default:
       
   236             User::Leave(KErrArgument);
       
   237         }
       
   238     )
       
   239     return errNo;
       
   240 }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 /**
       
   244  * Function execute activity framework functinality and return results 
       
   245  */
       
   246 int CAfStorageClientPrivate::execute(int function, RPointerArray<CAfEntry>& resultsList,const CAfEntry& templateEntry)
       
   247 {
       
   248     TRAPD(errNo, mImplementation.executeL(function, resultsList, templateEntry);)
       
   249     return errNo;
       
   250 }