28 #include <centralrepository.h> |
28 #include <centralrepository.h> |
29 #include <LogsDomainCRKeys.h> |
29 #include <LogsDomainCRKeys.h> |
30 |
30 |
31 // CONSTANTS |
31 // CONSTANTS |
32 |
32 |
|
33 // Telephony Configuration API |
|
34 // Keys under this category are used in defining telephony configuration. |
|
35 const TUid logsTelConfigurationCRUid = {0x102828B8}; |
|
36 |
|
37 // Amount of digits to be used in contact matching. |
|
38 // This allows a customer to variate the amount of digits to be matched. |
|
39 const TUint32 logsTelMatchDigits = 0x00000001; |
|
40 |
33 |
41 |
34 // ---------------------------------------------------------------------------- |
42 // ---------------------------------------------------------------------------- |
35 // LogsDbConnector::LogsDbConnector |
43 // LogsDbConnector::LogsDbConnector |
36 // ---------------------------------------------------------------------------- |
44 // ---------------------------------------------------------------------------- |
37 // |
45 // |
197 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::initL(), resource control enabled" ) |
204 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::initL(), resource control enabled" ) |
198 LogsCommonData::getInstance().configureReadSize( |
205 LogsCommonData::getInstance().configureReadSize( |
199 logsReadSizeCompressEnabled, LogsEvent::DirUndefined); |
206 logsReadSizeCompressEnabled, LogsEvent::DirUndefined); |
200 mCompressionEnabled = true; |
207 mCompressionEnabled = true; |
201 } |
208 } |
|
209 |
|
210 //Get number of digits used to match |
|
211 int matchLen; |
|
212 TRAPD( err, getTelNumMatchLenL(matchLen) ) |
|
213 if ( err ){ |
|
214 LOGS_QDEBUG( "logs [ENG] Getting tel num match len failed, use default" ); |
|
215 matchLen = logsDefaultMatchLength; |
|
216 } |
|
217 LOGS_QDEBUG_2( "logs [ENG] Tel number match length", matchLen ) |
|
218 LogsCommonData::getInstance().setTelNumMatchLen(matchLen); |
202 } |
219 } |
203 |
220 |
204 // ---------------------------------------------------------------------------- |
221 // ---------------------------------------------------------------------------- |
205 // LogsDbConnector::clearList |
222 // LogsDbConnector::clearList |
206 // ---------------------------------------------------------------------------- |
223 // ---------------------------------------------------------------------------- |
216 |
233 |
217 // ---------------------------------------------------------------------------- |
234 // ---------------------------------------------------------------------------- |
218 // LogsDbConnector::clearEvent |
235 // LogsDbConnector::clearEvent |
219 // ---------------------------------------------------------------------------- |
236 // ---------------------------------------------------------------------------- |
220 // |
237 // |
221 bool LogsDbConnector::clearEvents(const QList<int>& eventIds) |
238 bool LogsDbConnector::clearEvents(const QList<LogsEvent*>& events) |
222 { |
239 { |
223 bool asyncClearingStarted(false); |
240 bool asyncClearingStarted(false); |
224 if ( mLogsRemove ){ |
241 if ( mLogsRemove ){ |
225 bool async(false); |
242 bool async(false); |
226 int err = mLogsRemove->clearEvents(eventIds, async); |
243 int err = mLogsRemove->clearEvents(events, async); |
227 asyncClearingStarted = ( !err && async ); |
244 asyncClearingStarted = ( !err && async ); |
228 } |
245 } |
|
246 |
|
247 if ( asyncClearingStarted ){ |
|
248 // Lock reader while removing events one-by-one as reading |
|
249 // might have chance to run while removing is still in progress |
|
250 // which looks bad at UI layer. |
|
251 mReader->lock(true); |
|
252 } |
|
253 |
229 return asyncClearingStarted; |
254 return asyncClearingStarted; |
230 } |
255 } |
231 |
256 |
232 // ---------------------------------------------------------------------------- |
257 // ---------------------------------------------------------------------------- |
233 // LogsDbConnector::markEventsSeen |
258 // LogsDbConnector::markEventsSeen |
234 // ---------------------------------------------------------------------------- |
259 // ---------------------------------------------------------------------------- |
235 // |
260 // |
236 bool LogsDbConnector::markEventsSeen(const QList<int>& eventIds) |
261 bool LogsDbConnector::markEventsSeen(const QList<LogsEvent*>& events) |
237 { |
262 { |
238 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::markEventsSeen()" ) |
263 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::markEventsSeen()" ) |
239 |
264 |
240 if ( !mReader ){ |
265 if ( !mReader ){ |
241 return false; |
266 return false; |
242 } |
267 } |
243 |
268 |
244 foreach( int currId, eventIds ){ |
269 foreach( LogsEvent* ev, events ){ |
245 if ( !mEventsSeen.contains(currId) ){ |
270 if ( !mEventsSeen.contains(*ev) ){ |
246 mEventsSeen.append(currId); |
271 mEventsSeen.append(*ev); |
247 } |
272 foreach ( const LogsEvent& mergedEv, ev->mergedDuplicates() ){ |
248 } |
273 if ( !mEventsSeen.contains(mergedEv) ){ |
249 |
274 mEventsSeen.append(mergedEv); |
250 LOGS_QDEBUG_2( "logs [ENG] -> event ids:", mEventsSeen ); |
275 } |
|
276 } |
|
277 } |
|
278 } |
251 |
279 |
252 int err = doMarkEventSeen(); |
280 int err = doMarkEventSeen(); |
253 LOGS_QDEBUG_2( "logs [ENG] <- LogsDbConnector::markEventsSeen(), marking err:", |
281 LOGS_QDEBUG_2( "logs [ENG] <- LogsDbConnector::markEventsSeen(), marking err:", |
254 err ) |
282 err ) |
255 return ( err == 0 ); |
283 return ( err == 0 ); |
414 error = 0; |
442 error = 0; |
415 } |
443 } |
416 } |
444 } |
417 |
445 |
418 // ---------------------------------------------------------------------------- |
446 // ---------------------------------------------------------------------------- |
419 // LogsDbConnector::deleteRemoved |
447 // LogsDbConnector::deleteInvalidEvents |
420 // ---------------------------------------------------------------------------- |
448 // ---------------------------------------------------------------------------- |
421 // |
449 // |
422 void LogsDbConnector::deleteRemoved(int newEventCount) |
450 void LogsDbConnector::deleteInvalidEvents(int newEventCount) |
423 { |
451 { |
424 // Remove events which are not anymore in db nor in model, |
452 // Remove events which are not anymore in db nor in model, |
425 // such events are always at end of list |
453 // such events are always at end of list |
426 while ( mEvents.count() > newEventCount ){ |
454 while ( mEvents.count() > newEventCount ){ |
427 delete mEvents.takeLast(); |
455 delete mEvents.takeLast(); |
433 // ---------------------------------------------------------------------------- |
461 // ---------------------------------------------------------------------------- |
434 // |
462 // |
435 void LogsDbConnector::removeCompleted() |
463 void LogsDbConnector::removeCompleted() |
436 { |
464 { |
437 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::removeCompleted()" ) |
465 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::removeCompleted()" ) |
|
466 mReader->lock(false); |
438 emit clearingCompleted(0); |
467 emit clearingCompleted(0); |
439 LOGS_QDEBUG( "logs [ENG] <- LogsDbConnector::removeCompleted()" ) |
468 LOGS_QDEBUG( "logs [ENG] <- LogsDbConnector::removeCompleted()" ) |
440 } |
469 } |
441 |
470 |
442 // ---------------------------------------------------------------------------- |
471 // ---------------------------------------------------------------------------- |
445 // |
474 // |
446 void LogsDbConnector::logsRemoveErrorOccured(int err) |
475 void LogsDbConnector::logsRemoveErrorOccured(int err) |
447 { |
476 { |
448 LOGS_QDEBUG_2( "logs [ENG] <-> LogsDbConnector::logsRemoveErrorOccured(), err:", err ) |
477 LOGS_QDEBUG_2( "logs [ENG] <-> LogsDbConnector::logsRemoveErrorOccured(), err:", err ) |
449 |
478 |
|
479 mReader->lock(false); |
450 emit clearingCompleted(err); |
480 emit clearingCompleted(err); |
451 // TODO: error handling |
481 // TODO: error handling |
452 |
482 |
453 LOGS_QDEBUG( "logs [ENG] <- LogsDbConnector::logsRemoveErrorOccured()" ) |
483 LOGS_QDEBUG( "logs [ENG] <- LogsDbConnector::logsRemoveErrorOccured()" ) |
454 } |
484 } |
455 |
485 |
456 // ---------------------------------------------------------------------------- |
486 // ---------------------------------------------------------------------------- |
457 // LogsDbConnector::readCompleted |
487 // LogsDbConnector::readCompleted |
458 // ---------------------------------------------------------------------------- |
488 // ---------------------------------------------------------------------------- |
459 // |
489 // |
460 void LogsDbConnector::readCompleted(int readCount) |
490 void LogsDbConnector::readCompleted() |
461 { |
491 { |
462 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::readCompleted()" ) |
492 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::readCompleted()" ) |
463 LOGS_QDEBUG_EVENT_ARR(mEvents) |
493 LOGS_QDEBUG_EVENT_ARR(mEvents) |
464 |
494 |
465 // Find out updated, added and removed events |
495 // Find out updated, added and removed events |
466 mRemovedEventIndexes.clear(); |
496 mRemovedEventIndexes.clear(); |
467 mUpdatedEventIndexes.clear(); |
497 mUpdatedEventIndexes.clear(); |
468 mAddedEventIndexes.clear(); |
498 mAddedEventIndexes.clear(); |
|
499 mModelEvents.clear(); |
|
500 QList<LogsEvent*> toBeDeletedEvents; |
469 for ( int i = 0; i < mEvents.count(); i++ ){ |
501 for ( int i = 0; i < mEvents.count(); i++ ){ |
470 if ( !mEvents.at(i)->isInView() ){ |
502 LogsEvent* currEvent = mEvents.at(i); |
471 mRemovedEventIndexes.append( mEvents.at(i)->index() ); |
503 if ( !currEvent->isInView() ){ |
472 } else if ( mEvents.at(i)->eventState() == LogsEvent::EventUpdated ) { |
504 if ( currEvent->index() >= 0 ){ |
473 mUpdatedEventIndexes.append( mEvents.at(i)->index() ); |
505 mRemovedEventIndexes.append( currEvent->index() ); |
474 } else if ( mEvents.at(i)->eventState() == LogsEvent::EventAdded ) { |
506 } |
475 mAddedEventIndexes.append( mEvents.at(i)->index() ); |
507 toBeDeletedEvents.append( mEvents.takeAt(i) ); |
476 } |
508 i--; |
477 } |
509 } else { |
478 |
510 currEvent->setIndex(i); |
479 bool doModelDataReset( !mRemovedEventIndexes.isEmpty() || |
511 if ( currEvent->eventState() == LogsEvent::EventUpdated ) { |
480 !mAddedEventIndexes.isEmpty() || |
512 mUpdatedEventIndexes.append(i); |
481 !mUpdatedEventIndexes.isEmpty() ); |
513 } else if ( currEvent->eventState() == LogsEvent::EventAdded ) { |
482 if ( doModelDataReset ){ |
514 mAddedEventIndexes.append(i); |
483 mModelEvents.clear(); |
515 } |
484 int numValidEvents = qMin(mEvents.count(), readCount); |
516 mModelEvents.append(currEvent); |
485 for ( int i = 0; i < numValidEvents; i++ ){ |
|
486 mModelEvents.append(mEvents.at(i)); |
|
487 } |
517 } |
488 } |
518 } |
489 |
519 |
490 int changeCount = 0; |
520 int changeCount = 0; |
491 changeCount += mRemovedEventIndexes.isEmpty() ? 0 : 1; |
521 changeCount += mRemovedEventIndexes.isEmpty() ? 0 : 1; |