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