activityfw/activityserviceplugin/s60/src/afstorageproxy_p.cpp
author hgs
Wed, 06 Oct 2010 16:00:22 +0300
changeset 125 26079c1bb561
parent 119 50e220be30d1
permissions -rw-r--r--
201039_01
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
107
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include "afstorageproxy_p.h"
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
#include <fbs.h>
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
#include <QSize>
hgs
parents:
diff changeset
    23
#include <QPixmap>
119
hgs
parents: 116
diff changeset
    24
#include <QDateTime>
107
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
#include <XQConversions>
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
#include <afstorageglobals.h>
hgs
parents:
diff changeset
    29
#include <afstorageclient.h>
hgs
parents:
diff changeset
    30
#include <afentry.h>
hgs
parents:
diff changeset
    31
hgs
parents:
diff changeset
    32
#include "afstorageproxy.h"
hgs
parents:
diff changeset
    33
#include "afserializer.h"
hgs
parents:
diff changeset
    34
hgs
parents:
diff changeset
    35
AfStorageProxyPrivate::AfStorageProxyPrivate(AfStorageProxy *q) : mClient(0), q_ptr(q)
hgs
parents:
diff changeset
    36
{    
116
hgs
parents: 107
diff changeset
    37
    QT_TRAP_THROWING(
hgs
parents: 107
diff changeset
    38
        mClient = CAfStorageClient::NewL(*this);
hgs
parents: 107
diff changeset
    39
        User::LeaveIfError(mAppArcSession.Connect());
hgs
parents: 107
diff changeset
    40
    );
107
hgs
parents:
diff changeset
    41
}
hgs
parents:
diff changeset
    42
hgs
parents:
diff changeset
    43
AfStorageProxyPrivate::~AfStorageProxyPrivate()
hgs
parents:
diff changeset
    44
{
hgs
parents:
diff changeset
    45
    delete mClient;
116
hgs
parents: 107
diff changeset
    46
    mAppArcSession.Close();
107
hgs
parents:
diff changeset
    47
}
hgs
parents:
diff changeset
    48
116
hgs
parents: 107
diff changeset
    49
bool AfStorageProxyPrivate::saveActivity(int applicationId, const QString &activityId, const QString &customActivityName, const QVariant &activityData, const QVariantHash &metadata, const QPixmap &screenshot)
107
hgs
parents:
diff changeset
    50
{
hgs
parents:
diff changeset
    51
    int screenshotHandle(-1);
hgs
parents:
diff changeset
    52
    CFbsBitmap* bitmap(screenshot.toSymbianCFbsBitmap());
hgs
parents:
diff changeset
    53
    if (bitmap) {
hgs
parents:
diff changeset
    54
        screenshotHandle = bitmap->Handle();
hgs
parents:
diff changeset
    55
    }
hgs
parents:
diff changeset
    56
    
116
hgs
parents: 107
diff changeset
    57
    CAfEntry *entry = createSaveEntry(applicationId, activityId, customActivityName, activityData, metadata);
107
hgs
parents:
diff changeset
    58
    int result = mClient->saveActivity(*entry, screenshotHandle);    
hgs
parents:
diff changeset
    59
    delete entry;
hgs
parents:
diff changeset
    60
    delete bitmap;
hgs
parents:
diff changeset
    61
    
hgs
parents:
diff changeset
    62
    return KErrNone == result;
hgs
parents:
diff changeset
    63
}
hgs
parents:
diff changeset
    64
hgs
parents:
diff changeset
    65
bool AfStorageProxyPrivate::removeActivity(int applicationId, const QString &activityId)
hgs
parents:
diff changeset
    66
{
hgs
parents:
diff changeset
    67
    CAfEntry *entry = createFilterEntry(applicationId, activityId);
hgs
parents:
diff changeset
    68
    int result = mClient->removeActivity(*entry);
hgs
parents:
diff changeset
    69
    delete entry;
hgs
parents:
diff changeset
    70
    return KErrNone == result;
hgs
parents:
diff changeset
    71
}
hgs
parents:
diff changeset
    72
   
hgs
parents:
diff changeset
    73
bool AfStorageProxyPrivate::removeApplicationActivities(int applicationId)
hgs
parents:
diff changeset
    74
{
hgs
parents:
diff changeset
    75
    CAfEntry *entry = createFilterEntry(applicationId);
hgs
parents:
diff changeset
    76
    int result = mClient->removeApplicationActivities(*entry);
hgs
parents:
diff changeset
    77
    delete entry;
hgs
parents:
diff changeset
    78
    return KErrNone == result;
hgs
parents:
diff changeset
    79
}
hgs
parents:
diff changeset
    80
116
hgs
parents: 107
diff changeset
    81
bool AfStorageProxyPrivate::activities(QList<QVariantHash> &list, int limit)
107
hgs
parents:
diff changeset
    82
{
hgs
parents:
diff changeset
    83
    RPointerArray<CAfEntry> results;
hgs
parents:
diff changeset
    84
    
116
hgs
parents: 107
diff changeset
    85
    int result = mClient->activities(results, limit);
107
hgs
parents:
diff changeset
    86
    list.clear();
hgs
parents:
diff changeset
    87
    for (int i=0; i < results.Count(); ++i) {
116
hgs
parents: 107
diff changeset
    88
        list.append(extractMetadata(results[i], false));
107
hgs
parents:
diff changeset
    89
    }
hgs
parents:
diff changeset
    90
   
hgs
parents:
diff changeset
    91
    results.ResetAndDestroy();
hgs
parents:
diff changeset
    92
    return KErrNone == result;
hgs
parents:
diff changeset
    93
}
hgs
parents:
diff changeset
    94
hgs
parents:
diff changeset
    95
bool AfStorageProxyPrivate::applicationActivities(QStringList &list, int applicationId)
hgs
parents:
diff changeset
    96
{
hgs
parents:
diff changeset
    97
    RPointerArray<CAfEntry> results;
hgs
parents:
diff changeset
    98
    
hgs
parents:
diff changeset
    99
    CAfEntry *entry = createFilterEntry(applicationId);
hgs
parents:
diff changeset
   100
    int result = mClient->applicationActivities(results, *entry);
hgs
parents:
diff changeset
   101
    delete entry;
hgs
parents:
diff changeset
   102
    
hgs
parents:
diff changeset
   103
    list.clear();
hgs
parents:
diff changeset
   104
    for (int i=0; i < results.Count(); ++i) {
hgs
parents:
diff changeset
   105
        list.append(XQConversions::s60DescToQString(results[i]->ActivityId()));
hgs
parents:
diff changeset
   106
    }
hgs
parents:
diff changeset
   107
   
hgs
parents:
diff changeset
   108
    results.ResetAndDestroy();
hgs
parents:
diff changeset
   109
    return KErrNone == result;
hgs
parents:
diff changeset
   110
}
hgs
parents:
diff changeset
   111
hgs
parents:
diff changeset
   112
bool AfStorageProxyPrivate::activityData(QVariant &data, int applicationId, const QString &activityId)
hgs
parents:
diff changeset
   113
{
hgs
parents:
diff changeset
   114
    CAfEntry *entry = getEntry(applicationId, activityId);
hgs
parents:
diff changeset
   115
    
hgs
parents:
diff changeset
   116
    if (!entry) {
hgs
parents:
diff changeset
   117
        return false;
hgs
parents:
diff changeset
   118
    }
hgs
parents:
diff changeset
   119
    
hgs
parents:
diff changeset
   120
    QVariantHash deserializedData;
hgs
parents:
diff changeset
   121
    deserializedData << entry->Data(CAfEntry::Private);
hgs
parents:
diff changeset
   122
    data = deserializedData[ActivityDataKeyword];
hgs
parents:
diff changeset
   123
    delete entry;
hgs
parents:
diff changeset
   124
    return true;
hgs
parents:
diff changeset
   125
}
hgs
parents:
diff changeset
   126
hgs
parents:
diff changeset
   127
bool AfStorageProxyPrivate::activityMetaData(QVariantHash &metadata, int applicationId, const QString &activityId)
hgs
parents:
diff changeset
   128
{
hgs
parents:
diff changeset
   129
    CAfEntry *entry = getEntry(applicationId, activityId);
hgs
parents:
diff changeset
   130
    
hgs
parents:
diff changeset
   131
    if (entry) {
116
hgs
parents: 107
diff changeset
   132
        metadata = extractMetadata(entry, true);
107
hgs
parents:
diff changeset
   133
        delete entry;
hgs
parents:
diff changeset
   134
        return true;
hgs
parents:
diff changeset
   135
    }    
hgs
parents:
diff changeset
   136
    
hgs
parents:
diff changeset
   137
    return false;
hgs
parents:
diff changeset
   138
}
hgs
parents:
diff changeset
   139
hgs
parents:
diff changeset
   140
bool AfStorageProxyPrivate::waitActivity()
hgs
parents:
diff changeset
   141
{
hgs
parents:
diff changeset
   142
    return KErrNone == mClient->waitActivity();
hgs
parents:
diff changeset
   143
}
hgs
parents:
diff changeset
   144
    
hgs
parents:
diff changeset
   145
bool AfStorageProxyPrivate::launchActivity(int applicationId, const QString &activityUri)
hgs
parents:
diff changeset
   146
{
hgs
parents:
diff changeset
   147
    CAfEntry *entry = createFilterEntry(applicationId, activityUri);
hgs
parents:
diff changeset
   148
    int result = mClient->launchActivity(*entry);
hgs
parents:
diff changeset
   149
    delete entry;
hgs
parents:
diff changeset
   150
    return KErrNone == result;
hgs
parents:
diff changeset
   151
}
hgs
parents:
diff changeset
   152
119
hgs
parents: 116
diff changeset
   153
bool AfStorageProxyPrivate::getThumbnail(const QString &imagePath, void *userData)
107
hgs
parents:
diff changeset
   154
{
hgs
parents:
diff changeset
   155
    HBufC *source = XQConversions::qStringToS60Desc(imagePath);
119
hgs
parents: 116
diff changeset
   156
    int result = mClient->getThumbnail(*source, userData);
107
hgs
parents:
diff changeset
   157
    delete source;
hgs
parents:
diff changeset
   158
    return KErrNone == result;
hgs
parents:
diff changeset
   159
}
hgs
parents:
diff changeset
   160
hgs
parents:
diff changeset
   161
bool AfStorageProxyPrivate::notifyDataChange()
hgs
parents:
diff changeset
   162
{
hgs
parents:
diff changeset
   163
    return KErrNone == mClient->notifyDataChange();
hgs
parents:
diff changeset
   164
}
hgs
parents:
diff changeset
   165
hgs
parents:
diff changeset
   166
hgs
parents:
diff changeset
   167
void AfStorageProxyPrivate::waitActivityRequestCompleted(int result, const TDesC8 &data)
hgs
parents:
diff changeset
   168
{
hgs
parents:
diff changeset
   169
    if (KErrCancel != result) {
hgs
parents:
diff changeset
   170
        waitActivity();
hgs
parents:
diff changeset
   171
    }
hgs
parents:
diff changeset
   172
    if (KErrNone == result) {
hgs
parents:
diff changeset
   173
        emit q_ptr->activityRequested(XQConversions::s60Desc8ToQString(data));
hgs
parents:
diff changeset
   174
    }
hgs
parents:
diff changeset
   175
}
hgs
parents:
diff changeset
   176
hgs
parents:
diff changeset
   177
void AfStorageProxyPrivate::getThumbnailRequestCompleted(int result, int bitmapHandle, void *userData)
hgs
parents:
diff changeset
   178
{
hgs
parents:
diff changeset
   179
    if (KErrNone == result) {
hgs
parents:
diff changeset
   180
        CFbsBitmap* bitmap = new CFbsBitmap();
hgs
parents:
diff changeset
   181
        if (KErrNone == bitmap->Duplicate(bitmapHandle)) {
hgs
parents:
diff changeset
   182
            emit q_ptr->thumbnailRequested(QPixmap::fromSymbianCFbsBitmap(bitmap), userData);
hgs
parents:
diff changeset
   183
        }
hgs
parents:
diff changeset
   184
        delete bitmap;
hgs
parents:
diff changeset
   185
    }
hgs
parents:
diff changeset
   186
}
hgs
parents:
diff changeset
   187
hgs
parents:
diff changeset
   188
void AfStorageProxyPrivate::dataChangeNotificationCompleted(int result)
hgs
parents:
diff changeset
   189
{
hgs
parents:
diff changeset
   190
    if (KErrCancel != result) {
hgs
parents:
diff changeset
   191
        notifyDataChange();
hgs
parents:
diff changeset
   192
    }
hgs
parents:
diff changeset
   193
    if (KErrNone == result) {
hgs
parents:
diff changeset
   194
        emit q_ptr->dataChanged();
hgs
parents:
diff changeset
   195
    }
hgs
parents:
diff changeset
   196
}
hgs
parents:
diff changeset
   197
 
hgs
parents:
diff changeset
   198
CAfEntry *AfStorageProxyPrivate::createFilterEntry(int applicationId, const QString &activityId)
hgs
parents:
diff changeset
   199
{   
hgs
parents:
diff changeset
   200
    CAfEntry *entry(0); 
119
hgs
parents: 116
diff changeset
   201
    QT_TRAP_THROWING(entry = CAfEntry::NewL(0, applicationId, TPtrC(static_cast<const TUint16*>(activityId.utf16())), KNullDesC(), KNullDesC(), KNullDesC8(), KNullDesC8(), TTime()));
107
hgs
parents:
diff changeset
   202
    return entry;
hgs
parents:
diff changeset
   203
}
hgs
parents:
diff changeset
   204
116
hgs
parents: 107
diff changeset
   205
CAfEntry *AfStorageProxyPrivate::createSaveEntry(int applicationId, const QString &activityId, const QString &customActivityName, const QVariant &activityData, const QVariantHash &metadata)
107
hgs
parents:
diff changeset
   206
{   
hgs
parents:
diff changeset
   207
    CAfEntry *entry(0); 
hgs
parents:
diff changeset
   208
    
hgs
parents:
diff changeset
   209
    QT_TRAP_THROWING(
hgs
parents:
diff changeset
   210
        int flags(0);
hgs
parents:
diff changeset
   211
        QVariantHash privData;
hgs
parents:
diff changeset
   212
        privData.insert(ActivityDataKeyword, activityData);
hgs
parents:
diff changeset
   213
        RBuf8 privateBuff;
hgs
parents:
diff changeset
   214
        RBuf8 publicBuff;
hgs
parents:
diff changeset
   215
        CleanupClosePushL(privateBuff);
hgs
parents:
diff changeset
   216
        CleanupClosePushL(publicBuff);
hgs
parents:
diff changeset
   217
        privateBuff << privData;
hgs
parents:
diff changeset
   218
        publicBuff << metadata;
hgs
parents:
diff changeset
   219
        
hgs
parents:
diff changeset
   220
        if (metadata.contains(ActivityPersistence) && metadata[ActivityPersistence].toBool()) {
hgs
parents:
diff changeset
   221
            flags |= CAfEntry::Persistent;
hgs
parents:
diff changeset
   222
        }
hgs
parents:
diff changeset
   223
        
hgs
parents:
diff changeset
   224
        if (metadata.contains(ActivityVisibility) && !metadata[ActivityVisibility].toBool()) {
hgs
parents:
diff changeset
   225
            flags |= CAfEntry::Invisible;
hgs
parents:
diff changeset
   226
        }
hgs
parents:
diff changeset
   227
        
hgs
parents:
diff changeset
   228
        HBufC *actBuff = XQConversions::qStringToS60Desc(activityId);
hgs
parents:
diff changeset
   229
        CleanupStack::PushL(actBuff);
116
hgs
parents: 107
diff changeset
   230
        
hgs
parents: 107
diff changeset
   231
        HBufC *customNameBuff = XQConversions::qStringToS60Desc(customActivityName);
hgs
parents: 107
diff changeset
   232
        CleanupStack::PushL(customNameBuff);
hgs
parents: 107
diff changeset
   233
        
107
hgs
parents:
diff changeset
   234
        entry = CAfEntry::NewL(flags, 
hgs
parents:
diff changeset
   235
                               applicationId, 
hgs
parents:
diff changeset
   236
                               *actBuff, 
116
hgs
parents: 107
diff changeset
   237
                               *customNameBuff,
107
hgs
parents:
diff changeset
   238
                               KNullDesC, 
hgs
parents:
diff changeset
   239
                               privateBuff, 
119
hgs
parents: 116
diff changeset
   240
                               publicBuff,
hgs
parents: 116
diff changeset
   241
                               convertQDateTimeToTTime(metadata[ActivityTimestamp].toDateTime()));
116
hgs
parents: 107
diff changeset
   242
        CleanupStack::PopAndDestroy(customNameBuff);
107
hgs
parents:
diff changeset
   243
        CleanupStack::PopAndDestroy(actBuff);
hgs
parents:
diff changeset
   244
        CleanupStack::PopAndDestroy(&publicBuff);
hgs
parents:
diff changeset
   245
        CleanupStack::PopAndDestroy(&privateBuff);
hgs
parents:
diff changeset
   246
    );
hgs
parents:
diff changeset
   247
    return entry;
hgs
parents:
diff changeset
   248
}
hgs
parents:
diff changeset
   249
hgs
parents:
diff changeset
   250
CAfEntry *AfStorageProxyPrivate::getEntry(int applicationId, const QString &activityId)
hgs
parents:
diff changeset
   251
{
hgs
parents:
diff changeset
   252
    CAfEntry *entry = createFilterEntry(applicationId, activityId);
hgs
parents:
diff changeset
   253
    CAfEntry *resultEntry(0);
hgs
parents:
diff changeset
   254
    int result = mClient->activityData(resultEntry, *entry);
hgs
parents:
diff changeset
   255
    delete entry;
hgs
parents:
diff changeset
   256
    
hgs
parents:
diff changeset
   257
    if (KErrNone != result) {
hgs
parents:
diff changeset
   258
        delete resultEntry;
hgs
parents:
diff changeset
   259
        resultEntry = 0;
hgs
parents:
diff changeset
   260
    }
hgs
parents:
diff changeset
   261
    
hgs
parents:
diff changeset
   262
    return resultEntry;
hgs
parents:
diff changeset
   263
}
hgs
parents:
diff changeset
   264
116
hgs
parents: 107
diff changeset
   265
QVariantHash AfStorageProxyPrivate::extractMetadata(CAfEntry *entry, bool includePublicData)
107
hgs
parents:
diff changeset
   266
{
hgs
parents:
diff changeset
   267
    QVariantHash metadata;
116
hgs
parents: 107
diff changeset
   268
    if (includePublicData) {
hgs
parents: 107
diff changeset
   269
        metadata << entry->Data(CAfEntry::Public);
hgs
parents: 107
diff changeset
   270
    }
107
hgs
parents:
diff changeset
   271
    metadata.insert(ActivityApplicationKeyword, entry->ApplicationId());
hgs
parents:
diff changeset
   272
    metadata.insert(ActivityActivityKeyword, XQConversions::s60DescToQString(entry->ActivityId()));
116
hgs
parents: 107
diff changeset
   273
    metadata.insert(ActivityApplicationName, activityDisplayText(entry));
107
hgs
parents:
diff changeset
   274
    metadata.insert(ActivityScreenshotKeyword, XQConversions::s60DescToQString(entry->ImageSrc()));
hgs
parents:
diff changeset
   275
    metadata.insert(ActivityPersistence, (entry->Flags() & CAfEntry::Persistent) ? true : false);
hgs
parents:
diff changeset
   276
    metadata.insert(ActivityVisibility, (entry->Flags() & CAfEntry::Invisible) ? false : true); 
119
hgs
parents: 116
diff changeset
   277
    metadata.insert(ActivityTimestamp, convertTTimeToQDateTime(entry->Timestamp())); 
107
hgs
parents:
diff changeset
   278
    return metadata;
hgs
parents:
diff changeset
   279
}
hgs
parents:
diff changeset
   280
116
hgs
parents: 107
diff changeset
   281
QString AfStorageProxyPrivate::activityDisplayText(CAfEntry *entry)
hgs
parents: 107
diff changeset
   282
{
hgs
parents: 107
diff changeset
   283
    if (entry->CustomActivityName().Compare(KNullDesC()) == 0) {
hgs
parents: 107
diff changeset
   284
        TApaAppInfo info;
hgs
parents: 107
diff changeset
   285
        mAppArcSession.GetAppInfo(info, TUid::Uid(entry->ApplicationId()));
hgs
parents: 107
diff changeset
   286
        return QString::fromUtf16(info.iShortCaption.Ptr(), info.iShortCaption.Length());        
hgs
parents: 107
diff changeset
   287
    } else {
hgs
parents: 107
diff changeset
   288
        return XQConversions::s60DescToQString(entry->CustomActivityName());
hgs
parents: 107
diff changeset
   289
    }
hgs
parents: 107
diff changeset
   290
}
119
hgs
parents: 116
diff changeset
   291
hgs
parents: 116
diff changeset
   292
// -----------------------------------------------------------------------------
hgs
parents: 116
diff changeset
   293
TTime AfStorageProxyPrivate::convertQDateTimeToTTime(const QDateTime &timestamp) const
hgs
parents: 116
diff changeset
   294
{
hgs
parents: 116
diff changeset
   295
    return TTime( _L( "19700000:" ) ) + TTimeIntervalSeconds( timestamp.toTime_t() ) +
hgs
parents: 116
diff changeset
   296
                         TTimeIntervalMicroSeconds( timestamp.time().msec() * 1000 );
hgs
parents: 116
diff changeset
   297
}
hgs
parents: 116
diff changeset
   298
hgs
parents: 116
diff changeset
   299
// -----------------------------------------------------------------------------
hgs
parents: 116
diff changeset
   300
QDateTime AfStorageProxyPrivate::convertTTimeToQDateTime(const TTime &s60Time) const
hgs
parents: 116
diff changeset
   301
{
hgs
parents: 116
diff changeset
   302
    TTime posixEpoch(_L("19700000:"));
hgs
parents: 116
diff changeset
   303
    TTimeIntervalSeconds secondsFrom;
hgs
parents: 116
diff changeset
   304
    TTimeIntervalMicroSeconds microSecondsFrom;
hgs
parents: 116
diff changeset
   305
    s60Time.SecondsFrom(posixEpoch, secondsFrom);
hgs
parents: 116
diff changeset
   306
    microSecondsFrom = s60Time.MicroSecondsFrom(posixEpoch);
hgs
parents: 116
diff changeset
   307
    QDateTime retVal = QDateTime::fromTime_t(secondsFrom.Int());
hgs
parents: 116
diff changeset
   308
    retVal = retVal.addMSecs((microSecondsFrom.Int64() % TInt64(1000000) ) / TInt64(1000));
hgs
parents: 116
diff changeset
   309
    return retVal;    
hgs
parents: 116
diff changeset
   310
}