activityfw/activityserviceplugin/src/afactivityclient.cpp
changeset 109 e0aa398e6810
parent 104 9b022b1f357c
child 115 3ab5c078b490
equal deleted inserted replaced
104:9b022b1f357c 109:e0aa398e6810
     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 <QCoreApplication>
       
    18 #include <QStringList>
       
    19 #include <QTimer>
       
    20 #include <QUrl>
       
    21 #include <QDebug>
       
    22 #include <QDir>
       
    23 
       
    24 #include <afstorageentry.h>
       
    25 #include <afstorageglobals.h>
       
    26 
       
    27 #include "afactivityclient.h"
       
    28 ActivityClient::ActivityClient(const QSharedPointer<AfStorageClient> &serviceProvider, QObject *parent) 
       
    29 : 
       
    30     QObject(parent),
       
    31     mServiceProvider(serviceProvider),
       
    32     mIsconnected(false)
       
    33 {
       
    34     mIsconnected = ( KErrNone == mServiceProvider->connect());
       
    35     if( mIsconnected) {
       
    36         mServiceProvider->waitActivity();
       
    37     }
       
    38     connect(mServiceProvider.data(), SIGNAL(activityRequested(QString)), this, SIGNAL(activityRequested(QString)));
       
    39 }
       
    40 
       
    41 ActivityClient::~ActivityClient()
       
    42 {
       
    43 }
       
    44 
       
    45 bool ActivityClient::addActivity(const QString &activityId, const QVariant &data, const QVariantHash &parameters)
       
    46 {
       
    47     bool result(mIsconnected);
       
    48     if (result) {
       
    49         QVariantHash publicData(parameters);
       
    50         
       
    51         QPixmap screenshot(publicData[ActivityScreenshotKeyword].value<QPixmap>());
       
    52         publicData.remove(ActivityScreenshotKeyword);
       
    53         
       
    54         RProcess process;
       
    55         publicData.insert(ActivityApplicationKeyword, static_cast<int>(process.SecureId().iId));
       
    56         publicData.insert(ActivityActivityKeyword, activityId);
       
    57         AfStorageEntry entry(process.SecureId().iId, activityId, data, publicData);
       
    58         result = (KErrNone == mServiceProvider->addActivity(entry, screenshot));
       
    59     }
       
    60     return result;
       
    61 }
       
    62 
       
    63 bool ActivityClient::removeActivity(const QString &activityId)
       
    64 {
       
    65     bool result(mIsconnected);
       
    66     if (result) {
       
    67         RProcess process;
       
    68         AfStorageEntry entry(process.SecureId().iId, activityId);
       
    69         result = (KErrNone == mServiceProvider->removeActivity(entry));
       
    70     }
       
    71     return result;
       
    72 }
       
    73 
       
    74 bool ActivityClient::updateActivity(const QString &activityId, const QVariant &data, const QVariantHash &parameters)
       
    75 {
       
    76     bool result(mIsconnected);
       
    77     if (result) {
       
    78         QVariantHash publicData(parameters);
       
    79         QPixmap screenshot(publicData[ActivityScreenshotKeyword].value<QPixmap>());
       
    80         publicData.remove(ActivityScreenshotKeyword);
       
    81         RProcess process;
       
    82         publicData.insert(ActivityApplicationKeyword, static_cast<int>(process.SecureId().iId));
       
    83         publicData.insert(ActivityActivityKeyword, activityId);
       
    84         AfStorageEntry entry(process.SecureId().iId, activityId, data, publicData);
       
    85         result = (KErrNone == mServiceProvider->updateActivity(entry, screenshot));
       
    86     }
       
    87     return result;
       
    88 }
       
    89 
       
    90 QList<QVariantHash> ActivityClient::activities() const
       
    91 {
       
    92     QList<QVariantHash> retVal;
       
    93     if (mIsconnected) {
       
    94         RProcess process;
       
    95         AfStorageEntry entry(process.SecureId().iId);
       
    96         QList<AfStorageEntry> activities;
       
    97         mServiceProvider->applicationActivities(activities, entry);
       
    98         
       
    99         QList<AfStorageEntry>::iterator iter(activities.begin());
       
   100         for (; activities.end() != iter; iter = activities.erase(iter)) {
       
   101             retVal.append((*iter).publicData());
       
   102         }
       
   103     }
       
   104     return retVal;
       
   105 }
       
   106 
       
   107 QVariant ActivityClient::activityData(const QString &activityId) const
       
   108 {
       
   109     QVariant data;
       
   110     if (mIsconnected) {
       
   111         RProcess process;
       
   112         AfStorageEntry entry(static_cast<int>(process.SecureId().iId), activityId), result;
       
   113         if (0 == mServiceProvider->activityData(result, entry)) {
       
   114             data = result.privateData();
       
   115         }
       
   116     }
       
   117     return data;
       
   118 }
       
   119 
       
   120 QVariantHash ActivityClient::parseCommandLine(const QStringList &commandLineParams) const
       
   121 {
       
   122      QVariantHash activityParams;
       
   123     int activityMarkerIndex = commandLineParams.indexOf("-activity");
       
   124     if (activityMarkerIndex != -1 && commandLineParams.count() - 1 > activityMarkerIndex) {
       
   125         QUrl activityUri = QUrl::fromEncoded(commandLineParams.at(activityMarkerIndex+1).toAscii());
       
   126         if (activityUri.scheme() == "appto") {
       
   127             QList<QPair<QString, QString> > parameters = activityUri.queryItems();
       
   128             for (QList<QPair<QString, QString> >::const_iterator i = parameters.constBegin(); i != parameters.constEnd(); ++i) {
       
   129                 activityParams.insert(i->first, i->second);
       
   130             }
       
   131 
       
   132             if (activityParams.contains("activityname") && !activityParams.value("activityname").toString().isEmpty()) {
       
   133                 return activityParams;
       
   134             }
       
   135         }
       
   136     }
       
   137     return QVariantHash();
       
   138 }