116
|
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 "tstaskmonitor_p.h"
|
|
18 |
#include "tstaskmonitor.h"
|
|
19 |
|
|
20 |
#include <eikenv.h>
|
|
21 |
#include <fbs.h>
|
|
22 |
#include <s32mem.h>
|
|
23 |
|
|
24 |
#include <XQConversions>
|
|
25 |
|
|
26 |
#include "tstaskmonitorclient.h"
|
|
27 |
#include "tstask.h"
|
127
|
28 |
#include "tsentrykey.h"
|
|
29 |
#include "tscliententry.h"
|
116
|
30 |
#include "tstaskchangeinfo.h"
|
|
31 |
#include "tsutils.h"
|
|
32 |
#include "tstaskmonitorhistory.h"
|
|
33 |
using TaskSwitcher::CleanupResetAndDestroyPushL;
|
|
34 |
|
|
35 |
TsTaskMonitorPrivate::TsTaskMonitorPrivate(TsTaskMonitor *q) : q_ptr(q), mClient(0), mWsSession(CEikonEnv::Static()->WsSession())
|
|
36 |
{
|
|
37 |
QT_TRAP_THROWING(mClient = CTsTaskMonitorClient::NewL());
|
|
38 |
mClient->Subscribe(*this);
|
|
39 |
}
|
|
40 |
|
|
41 |
TsTaskMonitorPrivate::~TsTaskMonitorPrivate()
|
|
42 |
{
|
127
|
43 |
mUpdateSet.ResetAndDestroy();
|
116
|
44 |
mClient->CancelSubscribe();
|
|
45 |
delete mClient;
|
|
46 |
}
|
|
47 |
|
|
48 |
|
|
49 |
QList<TsTaskChange> TsTaskMonitorPrivate::changeList(bool fullList)
|
|
50 |
{
|
|
51 |
QList<TsTaskChange> retVal;
|
127
|
52 |
QT_TRAP_THROWING(changeListL());
|
|
53 |
|
|
54 |
QList< QSharedPointer<CTsClientEntry> > taskList;
|
|
55 |
QList<TsTaskMonitorHistory> newTaskHistory;
|
|
56 |
for (int offset(0); 0 < mUpdateSet.Count(); ++offset) {
|
|
57 |
QSharedPointer<CTsClientEntry> content(mUpdateSet[0]);
|
|
58 |
taskList.append(content);
|
|
59 |
newTaskHistory.append(TsTaskMonitorHistory(content, offset));
|
|
60 |
mUpdateSet.Remove(0);
|
|
61 |
}
|
|
62 |
if (fullList) {
|
|
63 |
mTaskHistory.clear();
|
|
64 |
}
|
|
65 |
QList<int> insertsList = findInserts(newTaskHistory);
|
|
66 |
QList<int> deletesList = findDeletes(newTaskHistory);
|
|
67 |
QList<TsTaskMonitorHistory> newMinusInserts;
|
|
68 |
if (insertsList.count() > 0 ) {
|
|
69 |
newMinusInserts = substractInsertsFromNew(insertsList, newTaskHistory);
|
|
70 |
} else {
|
|
71 |
newMinusInserts = newTaskHistory;
|
|
72 |
}
|
|
73 |
QList<TsTaskMonitorHistory> interimList;
|
|
74 |
if (deletesList.count() > 0 ) {
|
|
75 |
retVal.append(getDeletesChangeset(deletesList));
|
|
76 |
interimList = substractDeletesFromOld(deletesList);
|
|
77 |
} else {
|
|
78 |
interimList = mTaskHistory;
|
|
79 |
}
|
|
80 |
retVal.append(findMovesAndUpdates(newMinusInserts, taskList, interimList));
|
|
81 |
if (mTaskHistory.isEmpty()) {
|
|
82 |
retVal.append(TsTaskChange(TsTaskChangeInfo(), QSharedPointer<TsTask>()));
|
|
83 |
}
|
|
84 |
retVal.append(getInsertsChangeset(insertsList, taskList));
|
|
85 |
mTaskHistory = newTaskHistory;
|
116
|
86 |
return retVal;
|
|
87 |
}
|
|
88 |
|
127
|
89 |
void TsTaskMonitorPrivate::changeListL()
|
116
|
90 |
{
|
127
|
91 |
mUpdateSet.ResetAndDestroy();
|
|
92 |
HBufC8 *data = mClient->TasksContentLC();
|
|
93 |
if (data->Size() == 0) {
|
|
94 |
User::Leave(KErrCorrupt);
|
116
|
95 |
}
|
127
|
96 |
RDesReadStream dataStream;
|
|
97 |
CleanupClosePushL(dataStream);
|
|
98 |
dataStream.Open(*data);
|
|
99 |
const int count(dataStream.ReadInt32L());
|
|
100 |
for (int offset(0); offset < count; ++offset) {
|
|
101 |
CTsClientEntry* entry = CTsClientEntry::NewLC(dataStream);
|
|
102 |
mUpdateSet.AppendL(entry);
|
|
103 |
CleanupStack::Pop(entry);
|
116
|
104 |
}
|
127
|
105 |
CleanupStack::PopAndDestroy(&dataStream);
|
|
106 |
CleanupStack::PopAndDestroy(data);
|
116
|
107 |
}
|
|
108 |
|
|
109 |
QDateTime TsTaskMonitorPrivate::dateTimeFromS60(const TTime &s60Time)
|
|
110 |
{
|
|
111 |
TTime posixEpoch(_L("19700000:"));
|
|
112 |
TTimeIntervalSeconds secondsFrom;
|
|
113 |
TTimeIntervalMicroSeconds microSecondsFrom;
|
|
114 |
s60Time.SecondsFrom(posixEpoch, secondsFrom);
|
|
115 |
microSecondsFrom = s60Time.MicroSecondsFrom(posixEpoch);
|
|
116 |
QDateTime retVal = QDateTime::fromTime_t(secondsFrom.Int());
|
|
117 |
retVal = retVal.addMSecs((microSecondsFrom.Int64() % TInt64(1000000) ) / TInt64(1000));
|
|
118 |
return retVal;
|
|
119 |
}
|
|
120 |
|
|
121 |
int TsTaskMonitorPrivate::findItemIndex(
|
|
122 |
const QList<TsTaskMonitorHistory> &historyList,
|
|
123 |
const TsTaskMonitorHistory &item )
|
|
124 |
{
|
|
125 |
for (int iter(0); iter < historyList.count(); iter++) {
|
127
|
126 |
if(historyList[iter] == item) {
|
116
|
127 |
return iter;
|
|
128 |
}
|
|
129 |
}
|
|
130 |
return -1;
|
|
131 |
}
|
|
132 |
|
|
133 |
QList<int> TsTaskMonitorPrivate::findInserts(
|
|
134 |
const QList<TsTaskMonitorHistory> &newHistory)
|
|
135 |
{
|
|
136 |
QList<int> retVal = QList<int>();
|
|
137 |
for (int iter(0); iter < newHistory.count(); iter++) {
|
|
138 |
if (findItemIndex(mTaskHistory, newHistory[iter]) == -1) {
|
|
139 |
retVal.append(iter);
|
|
140 |
}
|
|
141 |
}
|
|
142 |
return retVal;
|
|
143 |
}
|
|
144 |
|
|
145 |
QList<int> TsTaskMonitorPrivate::findDeletes(
|
|
146 |
const QList<TsTaskMonitorHistory> &newHistory)
|
|
147 |
{
|
|
148 |
QList<int> retVal = QList<int>();
|
|
149 |
//iterate backwards to keep order during model operations
|
|
150 |
for (int iter(mTaskHistory.count() -1); iter >= 0 ; iter--) {
|
|
151 |
if (findItemIndex(newHistory, mTaskHistory[iter]) == -1) {
|
|
152 |
retVal.append(iter);
|
|
153 |
}
|
|
154 |
}
|
|
155 |
return retVal;
|
|
156 |
}
|
|
157 |
|
|
158 |
QList<TsTaskChange> TsTaskMonitorPrivate::getDeletesChangeset(
|
|
159 |
const QList<int> &deleteList)
|
|
160 |
{
|
|
161 |
QList<TsTaskChange> retVal;
|
|
162 |
foreach (int index, deleteList) {
|
|
163 |
TsTaskChangeInfo deleteChange(TsTaskChangeInfo::KInvalidOffset,
|
|
164 |
index);
|
|
165 |
retVal.append(TsTaskChange(deleteChange, QSharedPointer<TsTask>()));
|
|
166 |
}
|
|
167 |
return retVal;
|
|
168 |
}
|
|
169 |
|
|
170 |
QList<TsTaskChange> TsTaskMonitorPrivate::getInsertsChangeset(const QList<int> &insertList,
|
127
|
171 |
const QList< QSharedPointer<CTsClientEntry> > &taskList)
|
116
|
172 |
{
|
|
173 |
QList<TsTaskChange> retVal;
|
|
174 |
foreach (int index, insertList) {
|
|
175 |
TsTaskChangeInfo insertChange(index,
|
|
176 |
TsTaskChangeInfo::KInvalidOffset);
|
|
177 |
retVal.append(TsTaskChange(
|
|
178 |
insertChange,
|
|
179 |
QSharedPointer<TsTask>(new TsTask(taskList[index], *this))));
|
|
180 |
}
|
|
181 |
return retVal;
|
|
182 |
}
|
|
183 |
|
|
184 |
QList<TsTaskMonitorHistory> TsTaskMonitorPrivate::substractInsertsFromNew(
|
|
185 |
const QList<int> &insertList,
|
|
186 |
const QList<TsTaskMonitorHistory> &newHistory )
|
|
187 |
{
|
|
188 |
QList<TsTaskMonitorHistory> retVal(newHistory);
|
|
189 |
for ( int iter(insertList.count() - 1); iter >= 0 ; iter--) {
|
|
190 |
retVal.removeAt(insertList[iter]);
|
|
191 |
}
|
|
192 |
return retVal;
|
|
193 |
}
|
|
194 |
|
|
195 |
QList<TsTaskMonitorHistory> TsTaskMonitorPrivate::substractDeletesFromOld(
|
|
196 |
const QList<int> &deleteList)
|
|
197 |
{
|
|
198 |
QList<TsTaskMonitorHistory> retVal(mTaskHistory);
|
|
199 |
for (int iter(0); iter < deleteList.count() ; iter++) {
|
|
200 |
retVal.removeAt(deleteList[iter]);
|
|
201 |
}
|
|
202 |
return retVal;
|
|
203 |
}
|
|
204 |
|
|
205 |
QList<TsTaskChange> TsTaskMonitorPrivate::findMovesAndUpdates(
|
|
206 |
const QList<TsTaskMonitorHistory> &newMinusInserts,
|
127
|
207 |
const QList< QSharedPointer<CTsClientEntry> > &taskList,
|
116
|
208 |
QList<TsTaskMonitorHistory> &workingList)
|
|
209 |
{
|
|
210 |
QList<TsTaskChange> retVal;
|
|
211 |
for (int newPos(0); newPos < newMinusInserts.count(); newPos++) {
|
|
212 |
//case 1 item has moved
|
|
213 |
int previousPos = findItemIndex(workingList, newMinusInserts[newPos]);
|
|
214 |
if (newPos != previousPos) {
|
|
215 |
TsTaskChangeInfo moveChange(newPos, previousPos);
|
|
216 |
retVal.append(
|
|
217 |
TsTaskChange(moveChange, QSharedPointer<TsTask>()));
|
|
218 |
workingList.move(previousPos, newPos);
|
|
219 |
}
|
|
220 |
// case 2 item has changed
|
|
221 |
if (newMinusInserts[newPos].isUpdated(workingList[newPos])) {
|
|
222 |
TsTaskChangeInfo updateChange(newPos, newPos);
|
|
223 |
retVal.append( TsTaskChange(
|
|
224 |
updateChange,
|
127
|
225 |
QSharedPointer<TsTask>(new TsTask(taskList[newMinusInserts[newPos].offset()], *this))));
|
116
|
226 |
}
|
|
227 |
}
|
|
228 |
return retVal;
|
|
229 |
}
|
|
230 |
|
|
231 |
void TsTaskMonitorPrivate::HandleRunningAppChange()
|
|
232 |
{
|
|
233 |
emit q_ptr->taskListChanged();
|
|
234 |
}
|
|
235 |
|
127
|
236 |
void TsTaskMonitorPrivate::openTask(const MTsEntry &entry)
|
116
|
237 |
{
|
127
|
238 |
QT_TRAP_THROWING(
|
|
239 |
HBufC8 *dataPtr = keyLC(entry);
|
|
240 |
TPtr8 dataBuf(dataPtr->Des());
|
|
241 |
mClient->OpenTask(dataBuf);
|
|
242 |
CleanupStack::PopAndDestroy(dataPtr);
|
|
243 |
)
|
116
|
244 |
}
|
|
245 |
|
127
|
246 |
void TsTaskMonitorPrivate::closeTask(const MTsEntry &entry)
|
|
247 |
{
|
|
248 |
QT_TRAP_THROWING(
|
|
249 |
HBufC8 *dataPtr = keyLC(entry);
|
|
250 |
TPtr8 dataBuf(dataPtr->Des());
|
|
251 |
mClient->CloseTask(dataBuf);
|
|
252 |
CleanupStack::PopAndDestroy(dataPtr);
|
|
253 |
)
|
|
254 |
}
|
|
255 |
|
|
256 |
HBufC8* TsTaskMonitorPrivate::keyLC(const MTsEntry &entry)
|
116
|
257 |
{
|
127
|
258 |
HBufC8 *dataPtr = HBufC8::NewLC(TTsEntryKey::Size());
|
|
259 |
TPtr8 dataBuf(dataPtr->Des());
|
|
260 |
|
|
261 |
RDesWriteStream dataStream;
|
|
262 |
CleanupClosePushL(dataStream);
|
|
263 |
dataStream.Open(dataBuf);
|
|
264 |
dataStream << entry.Key();
|
|
265 |
CleanupStack::PopAndDestroy(&dataStream);
|
|
266 |
|
|
267 |
return dataPtr;
|
116
|
268 |
}
|