activityfw/storage/client/src/afstorageclient.cpp
changeset 109 e0aa398e6810
parent 104 9b022b1f357c
child 121 0b3699f6c654
equal deleted inserted replaced
104:9b022b1f357c 109:e0aa398e6810
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 #include "afstorageclient.h"
    17 #include "afstorageclient.h"
       
    18 
       
    19 #include <e32debug.h>
       
    20 
    18 #include "afstorageclient_p.h"
    21 #include "afstorageclient_p.h"
    19 
    22 #include "afcmd.h"
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 /**
       
    26  * Two-phase constructor. Create and initialize instance
       
    27  * @return entry instance
       
    28  */
       
    29 EXPORT_C CAfStorageClient *CAfStorageClient::NewL(MAfAsyncRequestObserver &observer)
       
    30 {
       
    31     CAfStorageClient *self = CAfStorageClient::NewLC(observer);
       
    32     CleanupStack::Pop(self);
       
    33     return self;
       
    34 }
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 /**
       
    38  * Two-phase constructor. Create, initialize and push instance into cleanup stack
       
    39  * @return entry instance
       
    40  */
       
    41 EXPORT_C CAfStorageClient *CAfStorageClient::NewLC(MAfAsyncRequestObserver &observer)
       
    42 {
       
    43     CAfStorageClient *self = new (ELeave) CAfStorageClient();
       
    44     CleanupStack::PushL(self);
       
    45     self->ConstructL(observer);
       
    46     return self;
       
    47 }    
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 /**
       
    51  * Destructor
       
    52  */
       
    53 EXPORT_C CAfStorageClient::~CAfStorageClient()
       
    54 {
       
    55     delete d_ptr;
       
    56 }
       
    57     
    20 // -----------------------------------------------------------------------------
    58 // -----------------------------------------------------------------------------
    21 /**
    59 /**
    22  * Constructor
    60  * Constructor
    23  */
    61  */
    24 AfStorageClient::AfStorageClient(QObject *obj)
    62 CAfStorageClient::CAfStorageClient()
    25 :
    63 {
    26 QObject(obj),
    64 }
    27 d_ptr(0)
    65 
    28 {
    66 // -----------------------------------------------------------------------------
    29     d_ptr = new AfStorageClientPrivate(*this);
    67 /**
    30 }
    68  * 2nd phase of construction
    31 
    69  */
    32 // -----------------------------------------------------------------------------
    70 void CAfStorageClient::ConstructL(MAfAsyncRequestObserver &observer)
    33 /**
    71 {
    34  * Destructor
    72     d_ptr = CAfStorageClientPrivate::NewL(observer);
    35  */
       
    36 AfStorageClient::~AfStorageClient()
       
    37 {
       
    38     delete d_ptr;
       
    39 }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 /**
       
    43  * Establish connection with activity server
       
    44  * @return 0 on succees, error code otherwise
       
    45  */
       
    46 int AfStorageClient::connect()
       
    47 {
       
    48     return d_ptr->connect();
       
    49 }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 /**
       
    53  * Interface implementation.
       
    54  * @see int MAfAsyncRequestObserver::asyncRequestCompleated(int, int, const QString&)
       
    55  */
       
    56 void AfStorageClient::asyncRequestCompleated(int result,
       
    57                                              int requestType, 
       
    58                                              const QString& data)
       
    59 {
       
    60     switch (requestType) {
       
    61     case WaitActivity:
       
    62         if (KErrCancel != result) {
       
    63             waitActivity();
       
    64         }            
       
    65         if (KErrNone == result) {
       
    66             emit activityRequested(data);
       
    67         }
       
    68         
       
    69         break;
       
    70     }
       
    71 }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 /**
       
    75  * Interface implementation.
       
    76  * @see int MAfAsyncRequestObserver::asyncRequestCompleated(int, int, QPixmap&, void*)
       
    77  */
       
    78 void AfStorageClient::asyncRequestCompleated(int result,
       
    79                                              int requestType, 
       
    80                                              const QPixmap& pixmap,
       
    81                                              void* userData)
       
    82 {
       
    83     switch (requestType) {
       
    84     case GetThumbnail:
       
    85         emit thumbnailRequested(0 == result ? pixmap : QPixmap(), 
       
    86                                 userData);
       
    87         break;
       
    88     }
       
    89 }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 /**
       
    93  * Interface implementation.
       
    94  * @see int MAfAsyncRequestObserver::asyncRequestCompleated(int, int)
       
    95  */
       
    96 void AfStorageClient::asyncRequestCompleated(int result,int requestType)
       
    97 {
       
    98     switch(requestType) {
       
    99     case NotifyChange:
       
   100         if (KErrCancel != result) {
       
   101             notifyDataChange();
       
   102         }
       
   103         if (KErrNone == result) {
       
   104             emit dataChanged();
       
   105         }
       
   106         break;
       
   107     }
       
   108 }
    73 }
   109 
    74 
   110 // -----------------------------------------------------------------------------
    75 // -----------------------------------------------------------------------------
   111 /**
    76 /**
   112  * Function add new activity
    77  * Function add new activity
   113  * @param entry - activity entry data structure
    78  * @param entry - activity entry data structure
   114  * @param imageSource - source for activity thumbnail
    79  * @param imageHandle - handle for activity thumbnail
   115  * @return 0 on success, error code otherwise
    80  * @return 0 on success, error code otherwise
   116  */
    81  */
   117 int AfStorageClient::addActivity(const AfStorageEntry &entry, const QPixmap &imageSource)
    82 EXPORT_C int CAfStorageClient::addActivity(const CAfEntry &entry, TInt imageHandle)
   118 {
    83 {
   119     return d_ptr->addActivity(entry, imageSource);
    84     RDebug::Print(_L("This method is deprecated, please use CAfStorageClient::saveActivity instead"));
       
    85     return d_ptr->addActivity(entry, imageHandle);
   120 }
    86 }
   121 
    87 
   122 // -----------------------------------------------------------------------------
    88 // -----------------------------------------------------------------------------
   123 /**
    89 /**
   124  * Function update existing activity
    90  * Function update existing activity
   125  * @param entry - activity entry data structure
    91  * @param entry - activity entry data structure
   126  * @param imageSource - source for activity thumbnail
    92  * @param imageHandle - handle for activity thumbnail
   127  * @return 0 on success, error code otherwise
    93  * @return 0 on success, error code otherwise
   128  */
    94  */
   129 int AfStorageClient::updateActivity(const AfStorageEntry &entry, 
    95 EXPORT_C int CAfStorageClient::updateActivity(const CAfEntry &entry, TInt imageHandle)
   130                                     const QPixmap &imageSource)
    96 {
   131 {
    97     RDebug::Print(_L("This method is deprecated, please use CAfStorageClient::saveActivity instead"));
   132     return d_ptr->updateActivity(entry, imageSource);
    98     return d_ptr->updateActivity(entry, imageHandle);
       
    99 }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 /**
       
   103  * Function save an activity (add new one or update existing one)
       
   104  * @param entry - activity entry data structure
       
   105  * @param imageHandle - handle for activity thumbnail
       
   106  * @return 0 on success, error code otherwise
       
   107  */
       
   108 EXPORT_C int CAfStorageClient::saveActivity(const CAfEntry &entry, TInt imageHandle)
       
   109 {    
       
   110     return d_ptr->saveActivity(entry, imageHandle);
   133 }
   111 }
   134 
   112 
   135 // -----------------------------------------------------------------------------
   113 // -----------------------------------------------------------------------------
   136 /**
   114 /**
   137  * Function remove existing activity
   115  * Function remove existing activity
   138  * @param entry - activity entry template
   116  * @param entry - activity entry template
   139   * @return 0 on success, error code otherwise
   117   * @return 0 on success, error code otherwise
   140  */
   118  */
   141 int AfStorageClient::removeActivity(const AfStorageEntry &entry)
   119 EXPORT_C int CAfStorageClient::removeActivity(const CAfEntry &entry)
   142 {
   120 {
   143     return d_ptr->removeActivity(entry);
   121     return d_ptr->removeActivity(entry);
   144 }
   122 }
   145 
   123 
   146 // -----------------------------------------------------------------------------
   124 // -----------------------------------------------------------------------------
   147 /**
   125 /**
   148  * Function remove existing activities for application
   126  * Function remove existing activities for application
   149  * @param entry - activity entry template
   127  * @param entry - activity entry template
   150   * @return 0 on success, error code otherwise
   128   * @return 0 on success, error code otherwise
   151  */
   129  */
   152 int AfStorageClient::removeApplicationActivities(const AfStorageEntry &entry)
   130 EXPORT_C int CAfStorageClient::removeApplicationActivities(const CAfEntry &entry)
   153 {
   131 {
   154     return d_ptr->removeApplicationActivities(entry);
   132     return d_ptr->removeApplicationActivities(entry);
   155 }
   133 }
   156 
   134 
   157 // -----------------------------------------------------------------------------
   135 // -----------------------------------------------------------------------------
   158 /**
   136 /**
   159  * Function retreive public data for all activities
   137  * Function retreive public data for all activities
   160  * @param dst - list of results
   138  * @param dst - list of results
   161  * @return 0 on success, error code otherwise 
   139  * @return 0 on success, error code otherwise 
   162  */
   140  */
   163 int AfStorageClient::activities(QList<AfStorageEntry> &dst)
   141 EXPORT_C int CAfStorageClient::activities(RPointerArray<CAfEntry> &dst)
   164 {
   142 {
   165     return d_ptr->activities(dst);
   143     return d_ptr->activities(dst);
   166 }
   144 }
   167 
   145 
   168 // -----------------------------------------------------------------------------
   146 // -----------------------------------------------------------------------------
   170  * Function retreive public data for all application activities
   148  * Function retreive public data for all application activities
   171  * @param dst - list of results
   149  * @param dst - list of results
   172  * @param entry - activity template
   150  * @param entry - activity template
   173  * @return 0 on success, error code otherwise 
   151  * @return 0 on success, error code otherwise 
   174  */
   152  */
   175 int AfStorageClient::applicationActivities(QList<AfStorageEntry> &dst, 
   153 EXPORT_C int CAfStorageClient::applicationActivities(RPointerArray<CAfEntry> &dst, const CAfEntry &entry)
   176                                            const AfStorageEntry &entry)
       
   177 {
   154 {
   178     return d_ptr->applicationActivities(dst, entry);
   155     return d_ptr->applicationActivities(dst, entry);
   179 }
   156 }
   180 
   157 
   181 // -----------------------------------------------------------------------------
   158 // -----------------------------------------------------------------------------
   183  * Function retreive all data for requested activity
   160  * Function retreive all data for requested activity
   184  * @param dst - activity entry
   161  * @param dst - activity entry
   185  * @param entry - activity template
   162  * @param entry - activity template
   186  * @return 0 on success, error code otherwise 
   163  * @return 0 on success, error code otherwise 
   187  */
   164  */
   188 int AfStorageClient::activityData(AfStorageEntry &dst, const AfStorageEntry &entry)
   165 EXPORT_C int CAfStorageClient::activityData(CAfEntry *&dst, const CAfEntry &entry)
   189 {
   166 {
   190     return d_ptr->activityData(dst, entry);
   167     return d_ptr->activityData(dst, entry);
   191 }
   168 }
   192 
   169 
   193 // -----------------------------------------------------------------------------
   170 // -----------------------------------------------------------------------------
   194 /**
   171 /**
   195  * Function subscribe application for notyfication about requested activity changes
   172  * Function subscribe application for notyfication about requested activity changes
   196  * @return 0 on success, error code otherwise 
   173  * @return 0 on success, error code otherwise 
   197  */
   174  */
   198 int AfStorageClient::waitActivity()
   175 EXPORT_C int CAfStorageClient::waitActivity()
   199 {
   176 {
   200     return d_ptr->waitActivity();
   177     return d_ptr->waitActivity();
   201 }
   178 }
   202 
   179 
   203 // -----------------------------------------------------------------------------
   180 // -----------------------------------------------------------------------------
   204 /**
   181 /**
   205  * Function request activity change
   182  * Function request activity change
   206  * @param entry - activity template 
   183  * @param entry - activity template 
   207  * @return 0 on success, error code otherwise 
   184  * @return 0 on success, error code otherwise 
   208  */
   185  */
   209 int AfStorageClient::launchActivity(const AfStorageEntry &entry)
   186 EXPORT_C int CAfStorageClient::launchActivity(const CAfEntry &entry)
   210 {
   187 {
   211     return d_ptr->launchActivity(entry);
   188     return d_ptr->launchActivity(entry);
   212 }
   189 }
   213 
   190 
   214 // -----------------------------------------------------------------------------
   191 // -----------------------------------------------------------------------------
   215 int AfStorageClient::getThumbnail(QSize size, QString imagePath, void* userDdata)
   192 EXPORT_C int CAfStorageClient::getThumbnail(const TSize &size, const TDesC &imagePath, void *userData)
   216 {
   193 {
   217     return d_ptr->getThumbnail(size, imagePath, userDdata);
   194     return d_ptr->getThumbnail(size, imagePath, userData);
   218 }
   195 }
   219 
   196 
   220 // -----------------------------------------------------------------------------
   197 // -----------------------------------------------------------------------------
   221 /**
   198 /**
   222  * Function subscribe launcher for data model changes
   199  * Function subscribe launcher for data model changes
   223  * @return 0 on success, error code otherwise 
   200  * @return 0 on success, error code otherwise 
   224  */
   201  */
   225 int AfStorageClient::notifyDataChange()
   202 EXPORT_C int CAfStorageClient::notifyDataChange()
   226 {
   203 {
   227     return  d_ptr->notifyDataChange();
   204     return d_ptr->notifyDataChange();
   228 }
   205 }