25 #include "tsserviceobserver.h" |
25 #include "tsserviceobserver.h" |
26 #include "tsresourcemanager.h" |
26 #include "tsresourcemanager.h" |
27 |
27 |
28 |
28 |
29 // ----------------------------------------------------------------------------- |
29 // ----------------------------------------------------------------------------- |
30 LOCAL_C QVariantHash valueL( QObject *aModel, TInt aOffset ) |
30 LOCAL_C QVariantHash value( QObject *aModel, TInt aOffset ) |
31 { |
31 { |
32 QList<QVariantHash> items; |
32 QList<QVariantHash> items; |
33 QMetaObject::invokeMethod( aModel, |
33 QMetaObject::invokeMethod( aModel, |
34 "taskList", |
34 "taskList", |
35 Q_RETURN_ARG(QList<QVariantHash>, |
35 Q_RETURN_ARG(QList<QVariantHash>, |
36 items ) ); |
36 items ) ); |
37 if( aOffset >= items.count() ) |
37 return (items.count() > aOffset) ? items.at(aOffset) : QVariantHash(); |
38 { |
|
39 User::Leave(KErrCorrupt); |
|
40 } |
|
41 return items.at(aOffset); |
|
42 } |
38 } |
43 |
39 |
44 // ----------------------------------------------------------------------------- |
40 // ----------------------------------------------------------------------------- |
45 CTsService* CTsService::NewLC(MTsResourceManager& resources, QObject* model) |
41 CTsService* CTsService::NewLC(MTsResourceManager& resources, QObject* model) |
46 { |
42 { |
105 { |
101 { |
106 iModelObserver = aObserver; |
102 iModelObserver = aObserver; |
107 } |
103 } |
108 |
104 |
109 // ----------------------------------------------------------------------------- |
105 // ----------------------------------------------------------------------------- |
110 const TDesC& CTsService::DisplayNameL( TInt aOffset ) const |
106 const TDesC& CTsService::DisplayName( TInt aOffset ) const |
111 { |
107 { |
112 return StringValueL( aOffset, "TaskName" ); |
108 return StringValue( aOffset, "TaskName" ); |
113 } |
109 } |
114 |
110 |
115 // ----------------------------------------------------------------------------- |
111 // ----------------------------------------------------------------------------- |
116 TInt CTsService::IconHandleL( TInt aOffset ) const |
112 TInt CTsService::IconHandle( TInt aOffset ) const |
117 { |
113 { |
118 return IntValueL( aOffset, "TaskScreenshot" ); |
114 return IntValue( aOffset, "TaskScreenshot" ); |
119 } |
115 } |
120 |
116 |
121 // ----------------------------------------------------------------------------- |
117 // ----------------------------------------------------------------------------- |
122 TTime CTsService::TimestampL( TInt aOffset ) const |
118 TTime CTsService::Timestamp( TInt aOffset ) const |
123 { |
119 { |
124 return TimeValueL( aOffset, "TaskTimestamp" ); |
120 return TimeValue( aOffset, "TaskTimestamp" ); |
125 } |
121 } |
126 |
122 |
127 // ----------------------------------------------------------------------------- |
123 // ----------------------------------------------------------------------------- |
128 TTime CTsService::TimestampUpdateL(TInt offset) const |
124 TTime CTsService::TimestampUpdate(TInt offset) const |
129 { |
125 { |
130 return TimeValueL(offset, "TaskUpdateTimestamp"); |
126 return TimeValue(offset, "TaskUpdateTimestamp"); |
131 } |
127 } |
132 |
128 |
133 TTsModelItemKey CTsService::KeyL( TInt aOffset ) const |
129 TTsEntryKey CTsService::Key( TInt aOffset ) const |
134 { |
130 { |
135 return TTsModelItemKey( IntValueL( aOffset, "TaskId" ), |
131 return TTsEntryKey( IntValue( aOffset, "TaskId" ), |
136 reinterpret_cast<TInt>( this ) ); |
132 reinterpret_cast<TInt>( this ) ); |
137 } |
133 } |
138 |
134 |
139 // ----------------------------------------------------------------------------- |
135 // ----------------------------------------------------------------------------- |
140 TBool CTsService::IsActiveL( TInt aOffset ) const |
136 TBool CTsService::IsActive( TInt aOffset ) const |
141 { |
137 { |
142 return IntValueL( aOffset, "TaskIsRunning" ); |
138 return IntValue( aOffset, "TaskIsRunning" ); |
143 } |
139 } |
144 |
140 |
145 // ----------------------------------------------------------------------------- |
141 // ----------------------------------------------------------------------------- |
146 TBool CTsService::IsClosableL( TInt aOffset ) const |
142 TBool CTsService::IsClosable( TInt aOffset ) const |
147 { |
143 { |
148 return IntValueL( aOffset, "TaskCanBeClosed" ); |
144 return IntValue( aOffset, "TaskCanBeClosed" ); |
149 } |
145 } |
150 |
146 |
151 // ----------------------------------------------------------------------------- |
147 // ----------------------------------------------------------------------------- |
152 TBool CTsService::IsMandatoryL( TInt aOffset ) const |
148 TBool CTsService::IsMandatory( TInt aOffset ) const |
153 { |
149 { |
154 const QVariantHash values(valueL(iModel, aOffset)); |
150 const QVariantHash values(value(iModel, aOffset)); |
155 const QString key("TaskIsMandatory"); |
151 const QString key("TaskIsMandatory"); |
156 return values.contains(key) ? values.value(key).toInt() : ETrue; |
152 return values.contains(key) ? values.value(key).toInt() : ETrue; |
157 } |
153 } |
158 |
154 |
159 // ----------------------------------------------------------------------------- |
155 // ----------------------------------------------------------------------------- |
160 TBool CTsService::CloseL( TTsModelItemKey aKey ) const |
156 TBool CTsService::Close( TTsEntryKey aKey ) const |
161 { |
157 { |
162 bool result(false); |
158 bool result(false); |
163 QMetaObject::invokeMethod( iModel, |
159 QMetaObject::invokeMethod( iModel, |
164 "closeTask", |
160 "closeTask", |
165 Q_RETURN_ARG(bool, result), |
161 Q_RETURN_ARG(bool, result), |
166 Q_ARG(QVariant, aKey.Key() ) ); |
162 Q_ARG(QVariant, aKey.Key() ) ); |
167 return result; |
163 return result; |
168 } |
164 } |
169 |
165 |
170 // ----------------------------------------------------------------------------- |
166 // ----------------------------------------------------------------------------- |
171 TBool CTsService::LaunchL( TTsModelItemKey aKey ) const |
167 TBool CTsService::Launch( TTsEntryKey aKey ) const |
172 { |
168 { |
173 bool result(false); |
169 bool result(false); |
174 QMetaObject::invokeMethod( iModel, |
170 QMetaObject::invokeMethod( iModel, |
175 "openTask", |
171 "openTask", |
176 Q_RETURN_ARG(bool, result), |
172 Q_RETURN_ARG(bool, result), |
177 Q_ARG(QVariant, aKey.Key() ) ); |
173 Q_ARG(QVariant, aKey.Key() ) ); |
178 return result; |
174 return result; |
179 } |
175 } |
180 |
176 |
181 // ----------------------------------------------------------------------------- |
177 // ----------------------------------------------------------------------------- |
182 TInt CTsService::IntValueL( TInt aOffset, const char* aKey) const |
178 TInt CTsService::IntValue( TInt aOffset, const char* aKey) const |
183 { |
179 { |
184 return valueL(iModel, aOffset).value( aKey ).toInt(); |
180 return value(iModel, aOffset).value( aKey ).toInt(); |
185 } |
181 } |
186 |
182 |
187 // ----------------------------------------------------------------------------- |
183 // ----------------------------------------------------------------------------- |
188 TTime CTsService::TimeValueL(TInt aOffset, const char* aKey) const |
184 TTime CTsService::TimeValue(TInt aOffset, const char* aKey) const |
189 { |
185 { |
190 // Conversion between TTime which counts from year 0, and QDateTime which uses unix epoch (1st Jan 1970) |
186 // Conversion between TTime which counts from year 0, and QDateTime which uses unix epoch (1st Jan 1970) |
191 QDateTime timestamp = valueL( iModel, aOffset ).value( aKey ).toDateTime(); |
187 QDateTime timestamp = value( iModel, aOffset ).value( aKey ).toDateTime(); |
192 |
188 |
193 return TTime( _L( "19700000:" ) ) + TTimeIntervalSeconds( timestamp.toTime_t() ) + |
189 return TTime( _L( "19700000:" ) ) + TTimeIntervalSeconds( timestamp.toTime_t() ) + |
194 TTimeIntervalMicroSeconds( timestamp.time().msec() * 1000 ); |
190 TTimeIntervalMicroSeconds( timestamp.time().msec() * 1000 ); |
195 } |
191 } |
196 |
192 |
197 // ----------------------------------------------------------------------------- |
193 // ----------------------------------------------------------------------------- |
198 const TDesC& CTsService::StringValueL( TInt aOffset, const char* aKey ) const |
194 const TDesC& CTsService::StringValue( TInt aOffset, const char* aKey ) const |
199 { |
195 { |
200 delete iBuffer; |
196 delete iBuffer; |
201 const_cast<CTsService *>(this)->iBuffer = 0; |
197 iBuffer = 0; |
202 |
198 |
203 const QVariantHash item(valueL(iModel, aOffset)); |
199 const QVariantHash item(value(iModel, aOffset)); |
204 QT_TRYCATCH_LEAVING( |
200 try { |
205 const_cast<CTsService *>(this)->iBuffer = |
201 iBuffer = XQConversions::qStringToS60Desc(item.value(aKey).toString()); |
206 XQConversions::qStringToS60Desc(item.value(aKey).toString())); |
202 } catch(...) { |
207 return *iBuffer; |
203 } |
208 } |
204 return iBuffer ? *iBuffer : KNullDesC(); |
|
205 } |