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