107
|
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 |
|
|
18 |
#include "afstorageproxy_p.h"
|
|
19 |
|
|
20 |
#include <fbs.h>
|
|
21 |
|
|
22 |
#include <QSize>
|
|
23 |
#include <QPixmap>
|
|
24 |
|
|
25 |
#include <XQConversions>
|
|
26 |
|
|
27 |
#include <afstorageglobals.h>
|
|
28 |
#include <afstorageclient.h>
|
|
29 |
#include <afentry.h>
|
|
30 |
|
|
31 |
#include "afstorageproxy.h"
|
|
32 |
#include "afserializer.h"
|
|
33 |
|
|
34 |
AfStorageProxyPrivate::AfStorageProxyPrivate(AfStorageProxy *q) : mClient(0), q_ptr(q)
|
|
35 |
{
|
116
|
36 |
QT_TRAP_THROWING(
|
|
37 |
mClient = CAfStorageClient::NewL(*this);
|
|
38 |
User::LeaveIfError(mAppArcSession.Connect());
|
|
39 |
);
|
107
|
40 |
}
|
|
41 |
|
|
42 |
AfStorageProxyPrivate::~AfStorageProxyPrivate()
|
|
43 |
{
|
|
44 |
delete mClient;
|
116
|
45 |
mAppArcSession.Close();
|
107
|
46 |
}
|
|
47 |
|
116
|
48 |
bool AfStorageProxyPrivate::addActivity(int applicationId, const QString &activityId, const QString &customActivityName, const QVariant &activityData, const QVariantHash &metadata, const QPixmap &screenshot)
|
107
|
49 |
{
|
|
50 |
int screenshotHandle(-1);
|
|
51 |
CFbsBitmap* bitmap(screenshot.toSymbianCFbsBitmap());
|
|
52 |
if (bitmap) {
|
|
53 |
screenshotHandle = bitmap->Handle();
|
|
54 |
}
|
|
55 |
|
116
|
56 |
CAfEntry *entry = createSaveEntry(applicationId, activityId, customActivityName, activityData, metadata);
|
107
|
57 |
int result = mClient->addActivity(*entry, screenshotHandle);
|
|
58 |
delete entry;
|
|
59 |
delete bitmap;
|
|
60 |
|
|
61 |
return KErrNone == result;
|
|
62 |
}
|
|
63 |
|
116
|
64 |
bool AfStorageProxyPrivate::updateActivity(int applicationId, const QString &activityId, const QString &customActivityName, const QVariant &activityData, const QVariantHash &metadata, const QPixmap &screenshot)
|
107
|
65 |
{
|
|
66 |
int screenshotHandle(-1);
|
|
67 |
CFbsBitmap* bitmap(screenshot.toSymbianCFbsBitmap());
|
|
68 |
if (bitmap) {
|
|
69 |
screenshotHandle = bitmap->Handle();
|
|
70 |
}
|
|
71 |
|
116
|
72 |
CAfEntry *entry = createSaveEntry(applicationId, activityId, customActivityName, activityData, metadata);
|
107
|
73 |
int result = mClient->updateActivity(*entry, screenshotHandle);
|
|
74 |
delete entry;
|
|
75 |
delete bitmap;
|
|
76 |
|
|
77 |
return KErrNone == result;
|
|
78 |
}
|
|
79 |
|
116
|
80 |
bool AfStorageProxyPrivate::saveActivity(int applicationId, const QString &activityId, const QString &customActivityName, const QVariant &activityData, const QVariantHash &metadata, const QPixmap &screenshot)
|
107
|
81 |
{
|
|
82 |
int screenshotHandle(-1);
|
|
83 |
CFbsBitmap* bitmap(screenshot.toSymbianCFbsBitmap());
|
|
84 |
if (bitmap) {
|
|
85 |
screenshotHandle = bitmap->Handle();
|
|
86 |
}
|
|
87 |
|
116
|
88 |
CAfEntry *entry = createSaveEntry(applicationId, activityId, customActivityName, activityData, metadata);
|
107
|
89 |
int result = mClient->saveActivity(*entry, screenshotHandle);
|
|
90 |
delete entry;
|
|
91 |
delete bitmap;
|
|
92 |
|
|
93 |
return KErrNone == result;
|
|
94 |
}
|
|
95 |
|
|
96 |
bool AfStorageProxyPrivate::removeActivity(int applicationId, const QString &activityId)
|
|
97 |
{
|
|
98 |
CAfEntry *entry = createFilterEntry(applicationId, activityId);
|
|
99 |
int result = mClient->removeActivity(*entry);
|
|
100 |
delete entry;
|
|
101 |
return KErrNone == result;
|
|
102 |
}
|
|
103 |
|
|
104 |
bool AfStorageProxyPrivate::removeApplicationActivities(int applicationId)
|
|
105 |
{
|
|
106 |
CAfEntry *entry = createFilterEntry(applicationId);
|
|
107 |
int result = mClient->removeApplicationActivities(*entry);
|
|
108 |
delete entry;
|
|
109 |
return KErrNone == result;
|
|
110 |
}
|
|
111 |
|
116
|
112 |
bool AfStorageProxyPrivate::activities(QList<QVariantHash> &list, int limit)
|
107
|
113 |
{
|
|
114 |
RPointerArray<CAfEntry> results;
|
|
115 |
|
116
|
116 |
int result = mClient->activities(results, limit);
|
107
|
117 |
list.clear();
|
|
118 |
for (int i=0; i < results.Count(); ++i) {
|
116
|
119 |
list.append(extractMetadata(results[i], false));
|
107
|
120 |
}
|
|
121 |
|
|
122 |
results.ResetAndDestroy();
|
|
123 |
return KErrNone == result;
|
|
124 |
}
|
|
125 |
|
|
126 |
bool AfStorageProxyPrivate::applicationActivities(QStringList &list, int applicationId)
|
|
127 |
{
|
|
128 |
RPointerArray<CAfEntry> results;
|
|
129 |
|
|
130 |
CAfEntry *entry = createFilterEntry(applicationId);
|
|
131 |
int result = mClient->applicationActivities(results, *entry);
|
|
132 |
delete entry;
|
|
133 |
|
|
134 |
list.clear();
|
|
135 |
for (int i=0; i < results.Count(); ++i) {
|
|
136 |
list.append(XQConversions::s60DescToQString(results[i]->ActivityId()));
|
|
137 |
}
|
|
138 |
|
|
139 |
results.ResetAndDestroy();
|
|
140 |
return KErrNone == result;
|
|
141 |
}
|
|
142 |
|
|
143 |
bool AfStorageProxyPrivate::activityData(QVariant &data, int applicationId, const QString &activityId)
|
|
144 |
{
|
|
145 |
CAfEntry *entry = getEntry(applicationId, activityId);
|
|
146 |
|
|
147 |
if (!entry) {
|
|
148 |
return false;
|
|
149 |
}
|
|
150 |
|
|
151 |
QVariantHash deserializedData;
|
|
152 |
deserializedData << entry->Data(CAfEntry::Private);
|
|
153 |
data = deserializedData[ActivityDataKeyword];
|
|
154 |
delete entry;
|
|
155 |
return true;
|
|
156 |
}
|
|
157 |
|
|
158 |
bool AfStorageProxyPrivate::activityMetaData(QVariantHash &metadata, int applicationId, const QString &activityId)
|
|
159 |
{
|
|
160 |
CAfEntry *entry = getEntry(applicationId, activityId);
|
|
161 |
|
|
162 |
if (entry) {
|
116
|
163 |
metadata = extractMetadata(entry, true);
|
107
|
164 |
delete entry;
|
|
165 |
return true;
|
|
166 |
}
|
|
167 |
|
|
168 |
return false;
|
|
169 |
}
|
|
170 |
|
|
171 |
bool AfStorageProxyPrivate::waitActivity()
|
|
172 |
{
|
|
173 |
return KErrNone == mClient->waitActivity();
|
|
174 |
}
|
|
175 |
|
|
176 |
bool AfStorageProxyPrivate::launchActivity(int applicationId, const QString &activityUri)
|
|
177 |
{
|
|
178 |
CAfEntry *entry = createFilterEntry(applicationId, activityUri);
|
|
179 |
int result = mClient->launchActivity(*entry);
|
|
180 |
delete entry;
|
|
181 |
return KErrNone == result;
|
|
182 |
}
|
|
183 |
|
|
184 |
bool AfStorageProxyPrivate::getThumbnail(const QSize &size, const QString &imagePath, void *userData)
|
|
185 |
{
|
|
186 |
HBufC *source = XQConversions::qStringToS60Desc(imagePath);
|
|
187 |
int result = mClient->getThumbnail(TSize(size.width(), size.height()), *source, userData);
|
|
188 |
delete source;
|
|
189 |
return KErrNone == result;
|
|
190 |
}
|
|
191 |
|
|
192 |
bool AfStorageProxyPrivate::notifyDataChange()
|
|
193 |
{
|
|
194 |
return KErrNone == mClient->notifyDataChange();
|
|
195 |
}
|
|
196 |
|
|
197 |
|
|
198 |
void AfStorageProxyPrivate::waitActivityRequestCompleted(int result, const TDesC8 &data)
|
|
199 |
{
|
|
200 |
if (KErrCancel != result) {
|
|
201 |
waitActivity();
|
|
202 |
}
|
|
203 |
if (KErrNone == result) {
|
|
204 |
emit q_ptr->activityRequested(XQConversions::s60Desc8ToQString(data));
|
|
205 |
}
|
|
206 |
}
|
|
207 |
|
|
208 |
void AfStorageProxyPrivate::getThumbnailRequestCompleted(int result, int bitmapHandle, void *userData)
|
|
209 |
{
|
|
210 |
if (KErrNone == result) {
|
|
211 |
CFbsBitmap* bitmap = new CFbsBitmap();
|
|
212 |
if (KErrNone == bitmap->Duplicate(bitmapHandle)) {
|
|
213 |
emit q_ptr->thumbnailRequested(QPixmap::fromSymbianCFbsBitmap(bitmap), userData);
|
|
214 |
}
|
|
215 |
delete bitmap;
|
|
216 |
}
|
|
217 |
}
|
|
218 |
|
|
219 |
void AfStorageProxyPrivate::dataChangeNotificationCompleted(int result)
|
|
220 |
{
|
|
221 |
if (KErrCancel != result) {
|
|
222 |
notifyDataChange();
|
|
223 |
}
|
|
224 |
if (KErrNone == result) {
|
|
225 |
emit q_ptr->dataChanged();
|
|
226 |
}
|
|
227 |
}
|
|
228 |
|
|
229 |
CAfEntry *AfStorageProxyPrivate::createFilterEntry(int applicationId, const QString &activityId)
|
|
230 |
{
|
|
231 |
CAfEntry *entry(0);
|
116
|
232 |
QT_TRAP_THROWING(entry = CAfEntry::NewL(0, applicationId, TPtrC(static_cast<const TUint16*>(activityId.utf16())), KNullDesC(), KNullDesC(), KNullDesC8(), KNullDesC8()));
|
107
|
233 |
return entry;
|
|
234 |
}
|
|
235 |
|
116
|
236 |
CAfEntry *AfStorageProxyPrivate::createSaveEntry(int applicationId, const QString &activityId, const QString &customActivityName, const QVariant &activityData, const QVariantHash &metadata)
|
107
|
237 |
{
|
|
238 |
CAfEntry *entry(0);
|
|
239 |
|
|
240 |
QT_TRAP_THROWING(
|
|
241 |
int flags(0);
|
|
242 |
QVariantHash privData;
|
|
243 |
privData.insert(ActivityDataKeyword, activityData);
|
|
244 |
RBuf8 privateBuff;
|
|
245 |
RBuf8 publicBuff;
|
|
246 |
CleanupClosePushL(privateBuff);
|
|
247 |
CleanupClosePushL(publicBuff);
|
|
248 |
privateBuff << privData;
|
|
249 |
publicBuff << metadata;
|
|
250 |
|
|
251 |
if (metadata.contains(ActivityPersistence) && metadata[ActivityPersistence].toBool()) {
|
|
252 |
flags |= CAfEntry::Persistent;
|
|
253 |
}
|
|
254 |
|
|
255 |
if (metadata.contains(ActivityVisibility) && !metadata[ActivityVisibility].toBool()) {
|
|
256 |
flags |= CAfEntry::Invisible;
|
|
257 |
}
|
|
258 |
|
|
259 |
HBufC *actBuff = XQConversions::qStringToS60Desc(activityId);
|
|
260 |
CleanupStack::PushL(actBuff);
|
116
|
261 |
|
|
262 |
HBufC *customNameBuff = XQConversions::qStringToS60Desc(customActivityName);
|
|
263 |
CleanupStack::PushL(customNameBuff);
|
|
264 |
|
107
|
265 |
entry = CAfEntry::NewL(flags,
|
|
266 |
applicationId,
|
|
267 |
*actBuff,
|
116
|
268 |
*customNameBuff,
|
107
|
269 |
KNullDesC,
|
|
270 |
privateBuff,
|
|
271 |
publicBuff);
|
116
|
272 |
CleanupStack::PopAndDestroy(customNameBuff);
|
107
|
273 |
CleanupStack::PopAndDestroy(actBuff);
|
|
274 |
CleanupStack::PopAndDestroy(&publicBuff);
|
|
275 |
CleanupStack::PopAndDestroy(&privateBuff);
|
|
276 |
);
|
|
277 |
return entry;
|
|
278 |
}
|
|
279 |
|
|
280 |
CAfEntry *AfStorageProxyPrivate::getEntry(int applicationId, const QString &activityId)
|
|
281 |
{
|
|
282 |
CAfEntry *entry = createFilterEntry(applicationId, activityId);
|
|
283 |
CAfEntry *resultEntry(0);
|
|
284 |
int result = mClient->activityData(resultEntry, *entry);
|
|
285 |
delete entry;
|
|
286 |
|
|
287 |
if (KErrNone != result) {
|
|
288 |
delete resultEntry;
|
|
289 |
resultEntry = 0;
|
|
290 |
}
|
|
291 |
|
|
292 |
return resultEntry;
|
|
293 |
}
|
|
294 |
|
116
|
295 |
QVariantHash AfStorageProxyPrivate::extractMetadata(CAfEntry *entry, bool includePublicData)
|
107
|
296 |
{
|
|
297 |
QVariantHash metadata;
|
116
|
298 |
if (includePublicData) {
|
|
299 |
metadata << entry->Data(CAfEntry::Public);
|
|
300 |
}
|
107
|
301 |
metadata.insert(ActivityApplicationKeyword, entry->ApplicationId());
|
|
302 |
metadata.insert(ActivityActivityKeyword, XQConversions::s60DescToQString(entry->ActivityId()));
|
116
|
303 |
metadata.insert(ActivityApplicationName, activityDisplayText(entry));
|
107
|
304 |
metadata.insert(ActivityScreenshotKeyword, XQConversions::s60DescToQString(entry->ImageSrc()));
|
|
305 |
metadata.insert(ActivityPersistence, (entry->Flags() & CAfEntry::Persistent) ? true : false);
|
|
306 |
metadata.insert(ActivityVisibility, (entry->Flags() & CAfEntry::Invisible) ? false : true);
|
|
307 |
return metadata;
|
|
308 |
}
|
|
309 |
|
116
|
310 |
QString AfStorageProxyPrivate::activityDisplayText(CAfEntry *entry)
|
|
311 |
{
|
|
312 |
if (entry->CustomActivityName().Compare(KNullDesC()) == 0) {
|
|
313 |
TApaAppInfo info;
|
|
314 |
mAppArcSession.GetAppInfo(info, TUid::Uid(entry->ApplicationId()));
|
|
315 |
return QString::fromUtf16(info.iShortCaption.Ptr(), info.iShortCaption.Length());
|
|
316 |
} else {
|
|
317 |
return XQConversions::s60DescToQString(entry->CustomActivityName());
|
|
318 |
}
|
|
319 |
}
|