119
|
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 "activitytsmodel.h"
|
|
19 |
|
|
20 |
#include <stdexcept>
|
|
21 |
|
|
22 |
#include <QPixmap>
|
|
23 |
#include <QUrl>
|
|
24 |
|
|
25 |
#include <QServiceManager>
|
|
26 |
#include <XQSettingsManager>
|
|
27 |
|
|
28 |
#include "afstorageglobals.h"
|
125
|
29 |
#include "tsrunningapp.h"
|
|
30 |
#include "tsrunningappstorage.h"
|
|
31 |
#include "tswindowgroupsmonitor.h"
|
|
32 |
#include "tsresourcemanager.h"
|
119
|
33 |
|
|
34 |
QTM_USE_NAMESPACE
|
|
35 |
|
|
36 |
namespace {
|
|
37 |
const char KActivityManager[] = "com.nokia.qt.activities.ActivityManager";
|
|
38 |
|
|
39 |
const int KTsDeviceDialogUid = 0x2002677F;
|
|
40 |
const int KItemsLimit = 0x00000001;
|
|
41 |
}
|
|
42 |
|
125
|
43 |
ActivityTsModel::ActivityTsModel(QObject *parent) :
|
|
44 |
QObject(parent),
|
|
45 |
mMonitor(0),
|
|
46 |
mAfManager(0) ,
|
|
47 |
mMaxItems(10)
|
119
|
48 |
{
|
|
49 |
{
|
|
50 |
QServiceManager serviceManager;
|
|
51 |
mAfManager = serviceManager.loadInterface(KActivityManager);
|
|
52 |
if (mAfManager) {
|
|
53 |
mAfManager->setParent(this);
|
|
54 |
} else {
|
|
55 |
throw std::runtime_error("Cannot create critical com.nokia.qt.activities.ActivityManager service");
|
|
56 |
}
|
|
57 |
}
|
|
58 |
|
|
59 |
{
|
|
60 |
XQSettingsManager crManager;
|
|
61 |
QVariant itemsNumberVariant = crManager.readItemValue(XQCentralRepositorySettingsKey(KTsDeviceDialogUid, KItemsLimit), XQSettingsManager::TypeInt);
|
|
62 |
if (!itemsNumberVariant.isNull()) {
|
|
63 |
int number = itemsNumberVariant.toInt();
|
|
64 |
if (number > 0) {
|
|
65 |
mMaxItems = number;
|
|
66 |
}
|
|
67 |
}
|
|
68 |
}
|
|
69 |
|
|
70 |
connect(mAfManager, SIGNAL(dataChanged()), SLOT(getActivities()));
|
|
71 |
connect(mAfManager, SIGNAL(thumbnailReady(QPixmap,void*)), SLOT(convertScreenshotToThumbnail(QPixmap,void*)));
|
|
72 |
|
|
73 |
getActivities();
|
|
74 |
}
|
|
75 |
|
|
76 |
ActivityTsModel::~ActivityTsModel()
|
|
77 |
{
|
125
|
78 |
if (mMonitor) {
|
|
79 |
mMonitor->Cancel(*this);
|
|
80 |
}
|
119
|
81 |
qDeleteAll(mData);
|
|
82 |
}
|
|
83 |
|
125
|
84 |
void ActivityTsModel::HandleWindowGroupChanged(
|
|
85 |
MTsResourceManager& resources,
|
|
86 |
const MTsRunningApplicationStorage& storage)
|
|
87 |
{
|
|
88 |
Q_UNUSED(resources);
|
|
89 |
mRunningAppsUid.clear();
|
|
90 |
for (int i(0); i < storage.Count(); ++i) {
|
|
91 |
mRunningAppsUid.append(storage[i].UidL().iUid);
|
|
92 |
}
|
|
93 |
if(filterActivity()) {
|
|
94 |
emit dataChanged();
|
|
95 |
}
|
|
96 |
}
|
|
97 |
|
|
98 |
bool ActivityTsModel::filterActivity()
|
|
99 |
{
|
|
100 |
bool retVal(false);
|
|
101 |
mPublishedData.clear();
|
|
102 |
for (int i(0); i < mData.count(); ++i) {
|
|
103 |
if(!mRunningAppsUid.contains(mData[i]->data().value(ActivityApplicationKeyword).toInt())) {
|
|
104 |
mPublishedData.append(mData[i]);
|
|
105 |
retVal = true;
|
|
106 |
}
|
|
107 |
}
|
|
108 |
return retVal;
|
|
109 |
}
|
|
110 |
|
119
|
111 |
QList<QVariantHash> ActivityTsModel::taskList() const
|
|
112 |
{
|
125
|
113 |
return taskList(mPublishedData.count());
|
119
|
114 |
}
|
|
115 |
|
|
116 |
QList<QVariantHash> ActivityTsModel::taskList(int limit) const
|
|
117 |
{
|
|
118 |
QList<QVariantHash> result;
|
125
|
119 |
for (int i(0); i < limit && i < mPublishedData.count(); ++i) {
|
|
120 |
result.append(mPublishedData[i]->data());
|
119
|
121 |
}
|
|
122 |
return result;
|
|
123 |
}
|
125
|
124 |
|
119
|
125 |
bool ActivityTsModel::openTask(const QVariant &id)
|
|
126 |
{
|
|
127 |
foreach (const ActivityTsEntry *entry, mData) {
|
|
128 |
if (entry->data().value("TaskId") == id) {
|
|
129 |
QMetaObject::invokeMethod(mAfManager,
|
|
130 |
"launchActivity",
|
|
131 |
Q_ARG(QUrl, entry->data().value("Uri").toUrl()));
|
|
132 |
return true;
|
|
133 |
}
|
|
134 |
}
|
|
135 |
return false;
|
|
136 |
}
|
|
137 |
|
|
138 |
bool ActivityTsModel::closeTask(const QVariant &id)
|
|
139 |
{
|
|
140 |
// it's impossible to "close" activity
|
|
141 |
Q_UNUSED(id);
|
|
142 |
return false;
|
|
143 |
}
|
|
144 |
|
|
145 |
void ActivityTsModel::getActivities()
|
125
|
146 |
{
|
|
147 |
QList<ActivityTsEntry*> oldData(mData);
|
119
|
148 |
mData.clear();
|
|
149 |
|
|
150 |
QList<QVariantHash> activities;
|
|
151 |
QMetaObject::invokeMethod(mAfManager,
|
|
152 |
"activitiesList",
|
|
153 |
Q_RETURN_ARG(QList<QVariantHash>, activities),
|
|
154 |
Q_ARG(int, mMaxItems));
|
125
|
155 |
|
119
|
156 |
foreach (const QVariantHash &activityEntry, activities) {
|
125
|
157 |
ActivityTsEntry *reusableEntry = findEntryWithScreenshot(oldData, activityEntry);
|
|
158 |
if (reusableEntry) {
|
|
159 |
mData.append(reusableEntry);
|
|
160 |
oldData.removeAll(reusableEntry);
|
|
161 |
} else {
|
|
162 |
mData.append(new ActivityTsEntry(activityEntry));
|
119
|
163 |
|
125
|
164 |
QMetaObject::invokeMethod(
|
119
|
165 |
mAfManager,
|
|
166 |
"getThumbnail",
|
|
167 |
Q_ARG(QString, activityEntry.value(ActivityScreenshotKeyword).toString()),
|
|
168 |
Q_ARG(void *, mData.last()));
|
125
|
169 |
}
|
119
|
170 |
}
|
125
|
171 |
qDeleteAll(oldData);
|
119
|
172 |
|
125
|
173 |
filterActivity();
|
119
|
174 |
emit dataChanged();
|
|
175 |
}
|
|
176 |
|
125
|
177 |
ActivityTsEntry *ActivityTsModel::findEntryWithScreenshot(const QList<ActivityTsEntry*> &entryList, const QVariantHash &activityEntry)
|
|
178 |
{
|
|
179 |
foreach (ActivityTsEntry *entry, entryList) {
|
|
180 |
const QVariantHash data = entry->data();
|
|
181 |
if ((data.value(ActivityApplicationKeyword) == activityEntry.value(ActivityApplicationKeyword)) &&
|
|
182 |
(data.value(ActivityActivityKeyword) == activityEntry.value(ActivityActivityKeyword)) &&
|
|
183 |
(data.value("TaskTimestamp") == activityEntry.value(ActivityTimestamp)) &&
|
|
184 |
(data.value("TaskScreenshot") != -1)) {
|
|
185 |
return entry;
|
|
186 |
}
|
|
187 |
}
|
|
188 |
return 0;
|
|
189 |
}
|
|
190 |
|
119
|
191 |
void ActivityTsModel::convertScreenshotToThumbnail(const QPixmap &thumbnail, void *userData)
|
|
192 |
{
|
|
193 |
emit createThumbnail(thumbnail, 0, userData);
|
|
194 |
}
|
|
195 |
|
|
196 |
void ActivityTsModel::thumbnailCreated(const QPixmap &thumbnail, const void *userData)
|
125
|
197 |
{
|
119
|
198 |
foreach (ActivityTsEntry *activity, mData) {
|
|
199 |
if (activity == userData) {
|
|
200 |
activity->setThumbnail(thumbnail.toSymbianCFbsBitmap());
|
|
201 |
emit dataChanged();
|
|
202 |
break;
|
|
203 |
}
|
|
204 |
}
|
|
205 |
}
|
125
|
206 |
|
|
207 |
void ActivityTsModel::setResources(MTsResourceManager& resources)
|
|
208 |
{
|
|
209 |
if (mMonitor) {
|
|
210 |
mMonitor->Cancel(*this);
|
|
211 |
}
|
|
212 |
mMonitor = &resources.WsMonitor();
|
|
213 |
mMonitor->SubscribeL(*this);
|
|
214 |
}
|