102
|
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 <QStringList>
|
|
19 |
#include <QUrl>
|
|
20 |
|
|
21 |
#include <afstorageglobals.h>
|
|
22 |
|
107
|
23 |
#include "afactivities_global.h"
|
102
|
24 |
#include "afmanager.h"
|
|
25 |
#include "aflauncher.h"
|
|
26 |
|
107
|
27 |
AfManager::AfManager(const QSharedPointer<AfStorageProxy> &serviceProvider,
|
102
|
28 |
QObject *parent)
|
|
29 |
:
|
|
30 |
QObject(parent),
|
|
31 |
mServiceProvider(serviceProvider)
|
|
32 |
{
|
107
|
33 |
mServiceProvider->notifyDataChange();
|
102
|
34 |
connect(mServiceProvider.data(),
|
107
|
35 |
SIGNAL(thumbnailRequested(QPixmap,void*)),
|
102
|
36 |
this,
|
107
|
37 |
SIGNAL(thumbnailReady(QPixmap,void*)));
|
102
|
38 |
connect(mServiceProvider.data(),
|
|
39 |
SIGNAL(dataChanged()),
|
|
40 |
this,
|
|
41 |
SIGNAL(dataChanged()));
|
|
42 |
}
|
|
43 |
|
|
44 |
AfManager::~AfManager()
|
|
45 |
{
|
|
46 |
}
|
|
47 |
|
116
|
48 |
QList<QVariantHash> AfManager::activitiesList(int limit)
|
102
|
49 |
{
|
107
|
50 |
QList<QVariantHash> results;
|
116
|
51 |
mServiceProvider->activities(results, limit);
|
107
|
52 |
return results;
|
102
|
53 |
}
|
|
54 |
|
|
55 |
void AfManager::launchActivity(const QUrl &uri)
|
|
56 |
{
|
107
|
57 |
if (uri.scheme() != Af::KActivityScheme)
|
102
|
58 |
return;
|
|
59 |
|
|
60 |
bool conversionOk(false);
|
|
61 |
int applicationId = uri.host().toUInt(&conversionOk, 16);
|
|
62 |
if (!conversionOk)
|
|
63 |
return;
|
|
64 |
|
|
65 |
QVariantHash activity;
|
|
66 |
activity.insert(ActivityApplicationKeyword, applicationId);
|
|
67 |
|
|
68 |
QVariantHash parameters;
|
|
69 |
QList<QPair<QString, QString> > uriParams = uri.queryItems();
|
|
70 |
for (QList<QPair<QString, QString> >::const_iterator i = uriParams.constBegin(); i != uriParams.constEnd(); ++i) {
|
|
71 |
parameters.insert(i->first, i->second);
|
|
72 |
}
|
|
73 |
|
107
|
74 |
if (parameters.contains(Af::KActivityUriNameKey)) {
|
|
75 |
activity.insert(ActivityActivityKeyword, parameters.value(Af::KActivityUriNameKey).toString());
|
|
76 |
parameters.remove(Af::KActivityUriNameKey);
|
102
|
77 |
}
|
|
78 |
|
|
79 |
activity.insert(ActivityParametersKeyword, parameters);
|
|
80 |
|
|
81 |
launchActivity(activity);
|
|
82 |
}
|
|
83 |
|
|
84 |
void AfManager::launchActivity(const QString &uri)
|
|
85 |
{
|
|
86 |
qWarning("AfManager::launchActivity(const QString &uri) is deprecated, use AfManager::launchActivity(const QUrl &uri) instead");
|
|
87 |
launchActivity(QUrl(uri));
|
|
88 |
}
|
|
89 |
|
|
90 |
void AfManager::launchActivity(int applicationId, const QString &activityId, const QVariantHash& parameters)
|
|
91 |
{
|
|
92 |
QVariantHash activity;
|
|
93 |
activity.insert(ActivityApplicationKeyword, applicationId);
|
|
94 |
activity.insert(ActivityActivityKeyword, activityId);
|
|
95 |
activity.insert(ActivityParametersKeyword, parameters);
|
|
96 |
|
|
97 |
launchActivity(activity);
|
|
98 |
}
|
|
99 |
|
119
|
100 |
void AfManager::getThumbnail(const QString &thumbnailPath, void *data)
|
102
|
101 |
{
|
119
|
102 |
mServiceProvider->getThumbnail(thumbnailPath, data);
|
102
|
103 |
}
|
|
104 |
|
|
105 |
void AfManager::launchActivity(const QVariantHash& activity)
|
|
106 |
{
|
|
107 |
AfLauncher applicationLauncher;
|
|
108 |
int applicationId = activity.value(ActivityApplicationKeyword).toInt();
|
|
109 |
if (applicationLauncher.isRunning(applicationId)) {
|
107
|
110 |
mServiceProvider->launchActivity(applicationId, activityToUri(activity).toString());
|
102
|
111 |
} else {
|
|
112 |
applicationLauncher.startApplication(applicationId, activityToUri(activity));
|
|
113 |
}
|
|
114 |
}
|
|
115 |
|
|
116 |
QUrl AfManager::activityToUri(const QVariantHash& activity) const
|
|
117 |
{
|
|
118 |
QUrl uri;
|
107
|
119 |
uri.setScheme(Af::KActivityScheme);
|
102
|
120 |
uri.setHost(QString("%1").arg(activity.value(ActivityApplicationKeyword).toUInt(), 8, 16, QChar('0')));
|
|
121 |
|
|
122 |
if (activity.contains(ActivityActivityKeyword))
|
107
|
123 |
uri.addQueryItem(Af::KActivityUriNameKey, activity.value(ActivityActivityKeyword).toString());
|
102
|
124 |
|
|
125 |
QVariantHash parameters = activity.value(ActivityParametersKeyword).toHash();
|
|
126 |
foreach(const QString &key, parameters.keys()) {
|
|
127 |
uri.addQueryItem(key, parameters.value(key).toString());
|
|
128 |
}
|
|
129 |
return uri;
|
|
130 |
}
|