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 <QObject>
|
|
18 |
#include <QDateTime>
|
|
19 |
#include <QVariantHash>
|
|
20 |
|
|
21 |
#include <xqconversions.h>
|
|
22 |
|
|
23 |
#include "tsservice.h"
|
|
24 |
#include "tsmodelobserver.h"
|
|
25 |
#include "tsserviceobserver.h"
|
125
|
26 |
#include "tsresourcemanager.h"
|
|
27 |
|
116
|
28 |
|
|
29 |
// -----------------------------------------------------------------------------
|
127
|
30 |
LOCAL_C QVariantHash value( QObject *aModel, TInt aOffset )
|
116
|
31 |
{
|
|
32 |
QList<QVariantHash> items;
|
|
33 |
QMetaObject::invokeMethod( aModel,
|
|
34 |
"taskList",
|
|
35 |
Q_RETURN_ARG(QList<QVariantHash>,
|
|
36 |
items ) );
|
127
|
37 |
return (items.count() > aOffset) ? items.at(aOffset) : QVariantHash();
|
116
|
38 |
}
|
|
39 |
|
|
40 |
// -----------------------------------------------------------------------------
|
125
|
41 |
CTsService* CTsService::NewLC(MTsResourceManager& resources, QObject* model)
|
116
|
42 |
{
|
|
43 |
CTsService *self = new (ELeave)CTsService();
|
|
44 |
CleanupStack::PushL(self);
|
125
|
45 |
self->ConstructL(resources, model);
|
116
|
46 |
return self;
|
|
47 |
}
|
|
48 |
|
|
49 |
// -----------------------------------------------------------------------------
|
|
50 |
CTsService::CTsService()
|
|
51 |
{
|
|
52 |
//No implementation required
|
|
53 |
}
|
|
54 |
|
|
55 |
// -----------------------------------------------------------------------------
|
125
|
56 |
void CTsService::ConstructL( MTsResourceManager& resources, QObject* model )
|
116
|
57 |
{
|
|
58 |
iModel = model;
|
|
59 |
User::LeaveIfNull(iModel);
|
|
60 |
// @todo: add checking for all necessary methods
|
|
61 |
|
|
62 |
iServiceObserver = new TsServiceObserver(*this);
|
|
63 |
User::LeaveIfNull(iServiceObserver);
|
|
64 |
QObject::connect(iModel,
|
|
65 |
SIGNAL(dataChanged()),
|
|
66 |
iServiceObserver,
|
|
67 |
SLOT(dataChanged()));
|
125
|
68 |
QMetaObject::invokeMethod(iModel,
|
|
69 |
"setResources",
|
|
70 |
Q_ARG(MTsResourceManager&, resources));
|
116
|
71 |
}
|
|
72 |
|
|
73 |
// -----------------------------------------------------------------------------
|
|
74 |
CTsService::~CTsService()
|
|
75 |
{
|
|
76 |
delete iModel;
|
|
77 |
delete iServiceObserver;
|
|
78 |
delete iBuffer;
|
|
79 |
}
|
|
80 |
|
|
81 |
// -----------------------------------------------------------------------------
|
|
82 |
void CTsService::DataChanged()
|
|
83 |
{
|
|
84 |
if(0 != iModelObserver)
|
|
85 |
{
|
|
86 |
iModelObserver->DataChanged(*this);
|
|
87 |
}
|
|
88 |
}
|
|
89 |
// -----------------------------------------------------------------------------
|
|
90 |
TInt CTsService::Count() const
|
|
91 |
{
|
|
92 |
QList<QVariantHash> items;
|
|
93 |
QMetaObject::invokeMethod(iModel,
|
|
94 |
"taskList",
|
|
95 |
Q_RETURN_ARG(QList<QVariantHash>, items));
|
|
96 |
return items.count();
|
|
97 |
}
|
|
98 |
|
|
99 |
// -----------------------------------------------------------------------------
|
|
100 |
void CTsService::SetObserver( MTsModelObserver *aObserver )
|
|
101 |
{
|
|
102 |
iModelObserver = aObserver;
|
|
103 |
}
|
|
104 |
|
|
105 |
// -----------------------------------------------------------------------------
|
127
|
106 |
const TDesC& CTsService::DisplayName( TInt aOffset ) const
|
116
|
107 |
{
|
127
|
108 |
return StringValue( aOffset, "TaskName" );
|
116
|
109 |
}
|
|
110 |
|
|
111 |
// -----------------------------------------------------------------------------
|
127
|
112 |
TInt CTsService::IconHandle( TInt aOffset ) const
|
116
|
113 |
{
|
127
|
114 |
return IntValue( aOffset, "TaskScreenshot" );
|
116
|
115 |
}
|
|
116 |
|
|
117 |
// -----------------------------------------------------------------------------
|
127
|
118 |
TTime CTsService::Timestamp( TInt aOffset ) const
|
116
|
119 |
{
|
127
|
120 |
return TimeValue( aOffset, "TaskTimestamp" );
|
116
|
121 |
}
|
|
122 |
|
|
123 |
// -----------------------------------------------------------------------------
|
127
|
124 |
TTime CTsService::TimestampUpdate(TInt offset) const
|
116
|
125 |
{
|
127
|
126 |
return TimeValue(offset, "TaskUpdateTimestamp");
|
116
|
127 |
}
|
|
128 |
|
127
|
129 |
TTsEntryKey CTsService::Key( TInt aOffset ) const
|
116
|
130 |
{
|
127
|
131 |
return TTsEntryKey( IntValue( aOffset, "TaskId" ),
|
|
132 |
reinterpret_cast<TInt>( this ) );
|
116
|
133 |
}
|
|
134 |
|
|
135 |
// -----------------------------------------------------------------------------
|
127
|
136 |
TBool CTsService::IsActive( TInt aOffset ) const
|
116
|
137 |
{
|
127
|
138 |
return IntValue( aOffset, "TaskIsRunning" );
|
116
|
139 |
}
|
|
140 |
|
|
141 |
// -----------------------------------------------------------------------------
|
127
|
142 |
TBool CTsService::IsClosable( TInt aOffset ) const
|
116
|
143 |
{
|
127
|
144 |
return IntValue( aOffset, "TaskCanBeClosed" );
|
116
|
145 |
}
|
|
146 |
|
|
147 |
// -----------------------------------------------------------------------------
|
127
|
148 |
TBool CTsService::IsMandatory( TInt aOffset ) const
|
119
|
149 |
{
|
127
|
150 |
const QVariantHash values(value(iModel, aOffset));
|
125
|
151 |
const QString key("TaskIsMandatory");
|
|
152 |
return values.contains(key) ? values.value(key).toInt() : ETrue;
|
119
|
153 |
}
|
|
154 |
|
|
155 |
// -----------------------------------------------------------------------------
|
127
|
156 |
TBool CTsService::Close( TTsEntryKey aKey ) const
|
116
|
157 |
{
|
|
158 |
bool result(false);
|
|
159 |
QMetaObject::invokeMethod( iModel,
|
|
160 |
"closeTask",
|
|
161 |
Q_RETURN_ARG(bool, result),
|
|
162 |
Q_ARG(QVariant, aKey.Key() ) );
|
|
163 |
return result;
|
|
164 |
}
|
|
165 |
|
|
166 |
// -----------------------------------------------------------------------------
|
127
|
167 |
TBool CTsService::Launch( TTsEntryKey aKey ) const
|
116
|
168 |
{
|
|
169 |
bool result(false);
|
|
170 |
QMetaObject::invokeMethod( iModel,
|
|
171 |
"openTask",
|
|
172 |
Q_RETURN_ARG(bool, result),
|
|
173 |
Q_ARG(QVariant, aKey.Key() ) );
|
|
174 |
return result;
|
|
175 |
}
|
|
176 |
|
|
177 |
// -----------------------------------------------------------------------------
|
127
|
178 |
TInt CTsService::IntValue( TInt aOffset, const char* aKey) const
|
116
|
179 |
{
|
127
|
180 |
return value(iModel, aOffset).value( aKey ).toInt();
|
116
|
181 |
}
|
|
182 |
|
|
183 |
// -----------------------------------------------------------------------------
|
127
|
184 |
TTime CTsService::TimeValue(TInt aOffset, const char* aKey) const
|
116
|
185 |
{
|
|
186 |
// Conversion between TTime which counts from year 0, and QDateTime which uses unix epoch (1st Jan 1970)
|
127
|
187 |
QDateTime timestamp = value( iModel, aOffset ).value( aKey ).toDateTime();
|
116
|
188 |
|
|
189 |
return TTime( _L( "19700000:" ) ) + TTimeIntervalSeconds( timestamp.toTime_t() ) +
|
|
190 |
TTimeIntervalMicroSeconds( timestamp.time().msec() * 1000 );
|
|
191 |
}
|
|
192 |
|
|
193 |
// -----------------------------------------------------------------------------
|
127
|
194 |
const TDesC& CTsService::StringValue( TInt aOffset, const char* aKey ) const
|
116
|
195 |
{
|
|
196 |
delete iBuffer;
|
127
|
197 |
iBuffer = 0;
|
116
|
198 |
|
127
|
199 |
const QVariantHash item(value(iModel, aOffset));
|
|
200 |
try {
|
|
201 |
iBuffer = XQConversions::qStringToS60Desc(item.value(aKey).toString());
|
|
202 |
} catch(...) {
|
116
|
203 |
}
|
127
|
204 |
return iBuffer ? *iBuffer : KNullDesC();
|
|
205 |
}
|