|
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 FILES |
|
19 #include "logsdbconnector.h" |
|
20 #include "logsevent.h" |
|
21 #include "logsengdefs.h" |
|
22 #include "logsreader.h" |
|
23 #include "logslogger.h" |
|
24 #include "logsremove.h" |
|
25 #include "logscommondata.h" |
|
26 #include <logcli.h> |
|
27 #include <f32file.h> |
|
28 #include <centralrepository.h> |
|
29 #include <LogsDomainCRKeys.h> |
|
30 |
|
31 // CONSTANTS |
|
32 |
|
33 |
|
34 // ---------------------------------------------------------------------------- |
|
35 // LogsDbConnector::LogsDbConnector |
|
36 // ---------------------------------------------------------------------------- |
|
37 // |
|
38 LogsDbConnector::LogsDbConnector( |
|
39 QList<LogsEvent*>& events, bool checkAllEvents, bool resourceControl ) |
|
40 : QObject(), |
|
41 mModelEvents( events ), |
|
42 mCheckAllEvents( checkAllEvents ), |
|
43 mResourceControl( resourceControl ), |
|
44 mLogClient( 0 ), |
|
45 mReader( 0 ), |
|
46 mLogsRemove( 0 ), |
|
47 mRepository( 0 ), |
|
48 mCompressionEnabled(false) |
|
49 { |
|
50 LOGS_QDEBUG( "logs [ENG] <-> LogsDbConnector::LogsDbConnector()" ) |
|
51 mFsSession = new RFs(); |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------------------------------- |
|
55 // LogsDbConnector::~LogsDbConnector |
|
56 // ---------------------------------------------------------------------------- |
|
57 // |
|
58 LogsDbConnector::~LogsDbConnector() |
|
59 { |
|
60 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::~LogsDbConnector()" ) |
|
61 |
|
62 delete mReader; |
|
63 delete mLogsRemove; |
|
64 delete mLogClient; |
|
65 if ( mFsSession ){ |
|
66 mFsSession->Close(); |
|
67 } |
|
68 delete mFsSession; |
|
69 |
|
70 qDeleteAll( mEvents ); |
|
71 qDeleteAll( mDuplicatedEvents ); |
|
72 |
|
73 delete mRepository; |
|
74 |
|
75 LOGS_QDEBUG( "logs [ENG] <- LogsDbConnector::~LogsDbConnector()" ) |
|
76 } |
|
77 |
|
78 // ---------------------------------------------------------------------------- |
|
79 // LogsDbConnector::init |
|
80 // ---------------------------------------------------------------------------- |
|
81 // |
|
82 int LogsDbConnector::init() |
|
83 { |
|
84 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::init()" ) |
|
85 |
|
86 TRAPD( err, initL() ); |
|
87 handleTemporaryError(err); |
|
88 |
|
89 LOGS_QDEBUG_2( "logs [ENG] <- LogsDbConnector::init(), err:", err ) |
|
90 |
|
91 return err; |
|
92 } |
|
93 |
|
94 // ---------------------------------------------------------------------------- |
|
95 // LogsDbConnector::start |
|
96 // ---------------------------------------------------------------------------- |
|
97 // |
|
98 int LogsDbConnector::start() |
|
99 { |
|
100 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::start()" ) |
|
101 |
|
102 #ifdef LOGSDBCONNECTOR_SIMULATION |
|
103 |
|
104 LOGS_QDEBUG( "logs [ENG] Simulation enabled" ) |
|
105 int numEvents = 16; |
|
106 QList<int> indexes; |
|
107 for ( int i = 0; i < numEvents; i++ ){ |
|
108 QString number = QString("1223456%1").arg(i); |
|
109 LogsEvent* event = new LogsEvent; |
|
110 if ( i % 3 == 0 ){ |
|
111 event->setDirection(LogsEvent::DirMissed); |
|
112 number += QString("DirMissed"); |
|
113 } |
|
114 else if ( i % 2 == 0 ){ |
|
115 event->setDirection(LogsEvent::DirIn); |
|
116 number += QString("DirIn"); |
|
117 } else { |
|
118 event->setDirection(LogsEvent::DirOut); |
|
119 number += QString("DirOut"); |
|
120 } |
|
121 event->setNumber(number); |
|
122 mEvents.append(event); |
|
123 mModelEvents.append(event); |
|
124 indexes.append(i); |
|
125 } |
|
126 emit dataAdded( indexes ); |
|
127 return 0; |
|
128 |
|
129 #endif |
|
130 |
|
131 if ( !mReader ){ |
|
132 LOGS_QDEBUG( "logs [ENG] Not initialized, failure" ) |
|
133 return -1; |
|
134 } |
|
135 int err = mReader->start(); |
|
136 handleTemporaryError(err); |
|
137 |
|
138 LOGS_QDEBUG_2( "logs [ENG] <- LogsDbConnector::start(), err:", err ) |
|
139 return err; |
|
140 } |
|
141 |
|
142 |
|
143 // ---------------------------------------------------------------------------- |
|
144 // LogsDbConnector::updateDetails |
|
145 // ---------------------------------------------------------------------------- |
|
146 // |
|
147 int LogsDbConnector::updateDetails(bool clearCached) |
|
148 { |
|
149 if ( !mReader ){ |
|
150 LOGS_QDEBUG( "logs [ENG] Not initialized, failure" ) |
|
151 return -1; |
|
152 } |
|
153 mReader->updateDetails(clearCached); |
|
154 readCompleted( mEvents.count() ); //to notify of model update |
|
155 return 0; |
|
156 } |
|
157 |
|
158 // ---------------------------------------------------------------------------- |
|
159 // LogsDbConnector::stateChanged |
|
160 // ---------------------------------------------------------------------------- |
|
161 // |
|
162 void LogsDbConnector::initL() |
|
163 { |
|
164 if ( mReader ){ |
|
165 // Already initialized |
|
166 return; |
|
167 } |
|
168 User::LeaveIfError( mFsSession->Connect() ); |
|
169 mLogClient = CLogClient::NewL( *mFsSession ); |
|
170 mLogsRemove = new LogsRemove( *this, mCheckAllEvents ); |
|
171 |
|
172 TLogString logString; |
|
173 //Texts in LOGWRAP.RLS / LOGWRAP.RSS |
|
174 User::LeaveIfError( mLogClient->GetString( logString, R_LOG_DIR_IN ) ); |
|
175 mLogEventStrings.iInDirection = DESC_TO_QSTRING( logString ); |
|
176 User::LeaveIfError( mLogClient->GetString( logString, R_LOG_DIR_OUT ) ); |
|
177 mLogEventStrings.iOutDirection = DESC_TO_QSTRING( logString ); |
|
178 User::LeaveIfError( mLogClient->GetString( logString, R_LOG_DIR_MISSED ) ); |
|
179 mLogEventStrings.iMissedDirection = DESC_TO_QSTRING( logString ); |
|
180 //"Unknown" (Logwrap.rls) |
|
181 User::LeaveIfError( mLogClient->GetString( logString, R_LOG_REMOTE_UNKNOWN ) ); |
|
182 mLogEventStrings.iUnKnownRemote = DESC_TO_QSTRING( logString ); |
|
183 //"Incoming on alternate line" |
|
184 User::LeaveIfError( mLogClient->GetString( logString, R_LOG_DIR_IN_ALT ) ); |
|
185 mLogEventStrings.iInDirectionAlt = DESC_TO_QSTRING( logString ); |
|
186 User::LeaveIfError( mLogClient->GetString( logString, R_LOG_DIR_OUT_ALT ) ); |
|
187 mLogEventStrings.iOutDirectionAlt = DESC_TO_QSTRING( logString ); |
|
188 User::LeaveIfError( mLogClient->GetString( logString, R_LOG_DIR_FETCHED) ); |
|
189 mLogEventStrings.iFetched = DESC_TO_QSTRING( logString ); |
|
190 |
|
191 mReader = new LogsReader( |
|
192 *mFsSession, *mLogClient, mLogEventStrings, mEvents, *this, mCheckAllEvents ); |
|
193 |
|
194 mRepository = CRepository::NewL( KCRUidLogs ); |
|
195 |
|
196 if ( mResourceControl ){ |
|
197 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::initL(), resource control enabled" ) |
|
198 LogsCommonData::getInstance().configureReadSize( |
|
199 logsReadSizeCompressEnabled, LogsEvent::DirUndefined); |
|
200 mCompressionEnabled = true; |
|
201 } |
|
202 } |
|
203 |
|
204 // ---------------------------------------------------------------------------- |
|
205 // LogsDbConnector::clearList |
|
206 // ---------------------------------------------------------------------------- |
|
207 // |
|
208 bool LogsDbConnector::clearList(LogsModel::ClearType cleartype) |
|
209 { |
|
210 bool clearingStarted(false); |
|
211 if ( mLogsRemove ){ |
|
212 clearingStarted = mLogsRemove->clearList(cleartype); |
|
213 } |
|
214 return clearingStarted; |
|
215 } |
|
216 |
|
217 // ---------------------------------------------------------------------------- |
|
218 // LogsDbConnector::clearEvent |
|
219 // ---------------------------------------------------------------------------- |
|
220 // |
|
221 bool LogsDbConnector::clearEvents(const QList<int>& eventIds) |
|
222 { |
|
223 bool asyncClearingStarted(false); |
|
224 if ( mLogsRemove ){ |
|
225 bool async(false); |
|
226 int err = mLogsRemove->clearEvents(eventIds, async); |
|
227 asyncClearingStarted = ( !err && async ); |
|
228 } |
|
229 return asyncClearingStarted; |
|
230 } |
|
231 |
|
232 // ---------------------------------------------------------------------------- |
|
233 // LogsDbConnector::markEventsSeen |
|
234 // ---------------------------------------------------------------------------- |
|
235 // |
|
236 bool LogsDbConnector::markEventsSeen(const QList<int>& eventIds) |
|
237 { |
|
238 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::markEventsSeen()" ) |
|
239 |
|
240 if ( !mReader ){ |
|
241 return false; |
|
242 } |
|
243 |
|
244 foreach( int currId, eventIds ){ |
|
245 if ( !mEventsSeen.contains(currId) ){ |
|
246 mEventsSeen.append(currId); |
|
247 } |
|
248 } |
|
249 |
|
250 LOGS_QDEBUG_2( "logs [ENG] -> event ids:", mEventsSeen ); |
|
251 |
|
252 int err = doMarkEventSeen(); |
|
253 LOGS_QDEBUG_2( "logs [ENG] <- LogsDbConnector::markEventsSeen(), marking err:", |
|
254 err ) |
|
255 return ( err == 0 ); |
|
256 } |
|
257 |
|
258 // ---------------------------------------------------------------------------- |
|
259 // LogsDbConnector::clearMissedCallsCounter |
|
260 // ---------------------------------------------------------------------------- |
|
261 // |
|
262 int LogsDbConnector::clearMissedCallsCounter() |
|
263 { |
|
264 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::clearMissedCallsCounter()" ) |
|
265 if ( !mRepository ){ |
|
266 return -1; |
|
267 } |
|
268 TInt value(0); |
|
269 int err = mRepository->Get( KLogsNewMissedCalls, value ); |
|
270 if ( !err && value != 0 ){ |
|
271 err = mRepository->Set( KLogsNewMissedCalls, 0 ); |
|
272 } |
|
273 LOGS_QDEBUG_2( "logs [ENG] <- LogsDbConnector::clearMissedCallsCounter(), err", err ) |
|
274 return err; |
|
275 } |
|
276 |
|
277 // ---------------------------------------------------------------------------- |
|
278 // LogsDbConnector::readDuplicates |
|
279 // ---------------------------------------------------------------------------- |
|
280 // |
|
281 int LogsDbConnector::readDuplicates(int eventId) |
|
282 { |
|
283 LOGS_QDEBUG_2( "logs [ENG] -> LogsDbConnector::readDuplicates(), id", eventId ) |
|
284 if ( !mReader ){ |
|
285 return -1; |
|
286 } |
|
287 qDeleteAll(mDuplicatedEvents); |
|
288 mDuplicatedEvents.clear(); |
|
289 return mReader->readDuplicates(eventId); |
|
290 } |
|
291 |
|
292 // ---------------------------------------------------------------------------- |
|
293 // LogsDbConnector::takeDuplicates |
|
294 // ---------------------------------------------------------------------------- |
|
295 // |
|
296 QList<LogsEvent*> LogsDbConnector::takeDuplicates() |
|
297 { |
|
298 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::takeDuplicates()" ) |
|
299 QList<LogsEvent*> duplicates = mDuplicatedEvents; |
|
300 mDuplicatedEvents.clear(); |
|
301 LOGS_QDEBUG( "logs [ENG] <- LogsDbConnector::takeDuplicates()" ) |
|
302 return duplicates; |
|
303 } |
|
304 |
|
305 // ----------------------------------------------------------------------------- |
|
306 // Do refresh only if compression has been enabled. Monitoring for database |
|
307 // changes is restored and current database contents are read. |
|
308 // ----------------------------------------------------------------------------- |
|
309 // |
|
310 int LogsDbConnector::refreshData() |
|
311 { |
|
312 if ( !mResourceControl ){ |
|
313 return -1; |
|
314 } |
|
315 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::refreshData()" ) |
|
316 int err = 0; |
|
317 bool prevCompressionEnabled = mCompressionEnabled; |
|
318 mCompressionEnabled = false; |
|
319 LogsCommonData::getInstance().configureReadSize( |
|
320 logsReadSizeUndefined, LogsEvent::DirUndefined); |
|
321 if ( mReader ){ |
|
322 if ( prevCompressionEnabled && !mReader->IsActive() ){ |
|
323 err = mReader->start(); |
|
324 } |
|
325 } |
|
326 LOGS_QDEBUG( "logs [ENG] <- LogsDbConnector::refreshData()" ) |
|
327 return err; |
|
328 } |
|
329 |
|
330 // ----------------------------------------------------------------------------- |
|
331 // Compress data, only defined amount of events are kept in memory, others |
|
332 // are deleted and read back to memory once refreshData is called. Also |
|
333 // monitoring for database changes is disabled. |
|
334 // ----------------------------------------------------------------------------- |
|
335 // |
|
336 int LogsDbConnector::compressData() |
|
337 { |
|
338 if ( !mResourceControl ){ |
|
339 return -1; |
|
340 } |
|
341 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::compressData()" ) |
|
342 mCompressionEnabled = true; |
|
343 LogsCommonData::getInstance().configureReadSize( |
|
344 logsReadSizeCompressEnabled, LogsEvent::DirUndefined); |
|
345 if ( mReader ){ |
|
346 int numEventsLeftInMemory = qMin(mEvents.count(), logsReadSizeCompressEnabled ); |
|
347 // Simulate disappearing of compressed events |
|
348 QList<int> removedIndexes; |
|
349 for ( int i = 0; i < mEvents.count(); i++ ){ |
|
350 if ( i == 0 ){ |
|
351 mModelEvents.clear(); |
|
352 } |
|
353 if ( i < numEventsLeftInMemory ){ |
|
354 mModelEvents.append(mEvents.at(i)); |
|
355 } else { |
|
356 removedIndexes.append(mEvents.at(i)->index()); |
|
357 } |
|
358 } |
|
359 emit dataRemoved(removedIndexes); |
|
360 deleteRemoved( numEventsLeftInMemory ); |
|
361 mReader->stop(); |
|
362 } |
|
363 LOGS_QDEBUG( "logs [ENG] <- LogsDbConnector::compressData()" ) |
|
364 return 0; |
|
365 } |
|
366 |
|
367 // ---------------------------------------------------------------------------- |
|
368 // LogsDbConnector::predictiveSearchStatus |
|
369 // ---------------------------------------------------------------------------- |
|
370 // |
|
371 int LogsDbConnector::predictiveSearchStatus() |
|
372 { |
|
373 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::predictiveSearchStatus()" ) |
|
374 int status(-1); |
|
375 if ( mRepository ) { |
|
376 TInt value(0); |
|
377 status = mRepository->Get( KLogsPredictiveSearch, value ); |
|
378 if ( !status ) { |
|
379 status = value; |
|
380 } |
|
381 } |
|
382 LOGS_QDEBUG_2( "logs [ENG] <- LogsDbConnector::predictiveSearchStatus(), status:", |
|
383 status ) |
|
384 return status; |
|
385 } |
|
386 |
|
387 // ---------------------------------------------------------------------------- |
|
388 // LogsDbConnector::setPredictiveSearch |
|
389 // ---------------------------------------------------------------------------- |
|
390 // |
|
391 int LogsDbConnector::setPredictiveSearch(bool enabled) |
|
392 { |
|
393 int err(-1); |
|
394 int status = predictiveSearchStatus(); |
|
395 //if status == 0, it means that predictive search is permanently Off |
|
396 //and we are not allowed to modify it |
|
397 if (status != 0 && mRepository) { |
|
398 int value = enabled ? 1 : 2; |
|
399 err = mRepository->Set( KLogsPredictiveSearch, value ); |
|
400 } |
|
401 return err; |
|
402 } |
|
403 |
|
404 // ---------------------------------------------------------------------------- |
|
405 // LogsDbConnector::handleTemporaryError |
|
406 // ---------------------------------------------------------------------------- |
|
407 // |
|
408 void LogsDbConnector::handleTemporaryError(int& error) |
|
409 { |
|
410 if ( error == KErrAccessDenied ){ |
|
411 LOGS_QDEBUG( |
|
412 "logs [ENG] LogsDbConnector::handleTemporaryError, DB temp unavailable" ) |
|
413 // TODO: handle temporary error in some meaningful way |
|
414 error = 0; |
|
415 } |
|
416 } |
|
417 |
|
418 // ---------------------------------------------------------------------------- |
|
419 // LogsDbConnector::deleteRemoved |
|
420 // ---------------------------------------------------------------------------- |
|
421 // |
|
422 void LogsDbConnector::deleteRemoved(int newEventCount) |
|
423 { |
|
424 // Remove events which are not anymore in db nor in model, |
|
425 // such events are always at end of list |
|
426 while ( mEvents.count() > newEventCount ){ |
|
427 delete mEvents.takeLast(); |
|
428 } |
|
429 } |
|
430 |
|
431 // ---------------------------------------------------------------------------- |
|
432 // LogsDbConnector::removeCompleted |
|
433 // ---------------------------------------------------------------------------- |
|
434 // |
|
435 void LogsDbConnector::removeCompleted() |
|
436 { |
|
437 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::removeCompleted()" ) |
|
438 emit clearingCompleted(0); |
|
439 LOGS_QDEBUG( "logs [ENG] <- LogsDbConnector::removeCompleted()" ) |
|
440 } |
|
441 |
|
442 // ---------------------------------------------------------------------------- |
|
443 // LogsDbConnector::logsRemoveErrorOccured |
|
444 // ---------------------------------------------------------------------------- |
|
445 // |
|
446 void LogsDbConnector::logsRemoveErrorOccured(int err) |
|
447 { |
|
448 LOGS_QDEBUG_2( "logs [ENG] <-> LogsDbConnector::logsRemoveErrorOccured(), err:", err ) |
|
449 |
|
450 emit clearingCompleted(err); |
|
451 // TODO: error handling |
|
452 |
|
453 LOGS_QDEBUG( "logs [ENG] <- LogsDbConnector::logsRemoveErrorOccured()" ) |
|
454 } |
|
455 |
|
456 // ---------------------------------------------------------------------------- |
|
457 // LogsDbConnector::readCompleted |
|
458 // ---------------------------------------------------------------------------- |
|
459 // |
|
460 void LogsDbConnector::readCompleted(int readCount) |
|
461 { |
|
462 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::readCompleted()" ) |
|
463 LOGS_QDEBUG_EVENT_ARR(mEvents) |
|
464 |
|
465 // Find out updated, added and removed events |
|
466 mRemovedEventIndexes.clear(); |
|
467 mUpdatedEventIndexes.clear(); |
|
468 mAddedEventIndexes.clear(); |
|
469 for ( int i = 0; i < mEvents.count(); i++ ){ |
|
470 if ( !mEvents.at(i)->isInView() ){ |
|
471 mRemovedEventIndexes.append( mEvents.at(i)->index() ); |
|
472 } else if ( mEvents.at(i)->eventState() == LogsEvent::EventUpdated ) { |
|
473 mUpdatedEventIndexes.append( mEvents.at(i)->index() ); |
|
474 } else if ( mEvents.at(i)->eventState() == LogsEvent::EventAdded ) { |
|
475 mAddedEventIndexes.append( mEvents.at(i)->index() ); |
|
476 } |
|
477 } |
|
478 |
|
479 bool doModelDataReset( !mRemovedEventIndexes.isEmpty() || |
|
480 !mAddedEventIndexes.isEmpty() || |
|
481 !mUpdatedEventIndexes.isEmpty() ); |
|
482 if ( doModelDataReset ){ |
|
483 mModelEvents.clear(); |
|
484 int numValidEvents = qMin(mEvents.count(), readCount); |
|
485 for ( int i = 0; i < numValidEvents; i++ ){ |
|
486 mModelEvents.append(mEvents.at(i)); |
|
487 } |
|
488 } |
|
489 |
|
490 if ( !mRemovedEventIndexes.isEmpty() ){ |
|
491 emit dataRemoved(mRemovedEventIndexes); |
|
492 } |
|
493 if ( !mAddedEventIndexes.isEmpty() ){ |
|
494 emit dataAdded(mAddedEventIndexes); |
|
495 } |
|
496 if ( !mUpdatedEventIndexes.isEmpty() ){ |
|
497 emit dataUpdated(mUpdatedEventIndexes); |
|
498 } |
|
499 |
|
500 deleteRemoved(readCount); |
|
501 |
|
502 if ( mCompressionEnabled ){ |
|
503 mReader->stop(); |
|
504 } |
|
505 |
|
506 LOGS_QDEBUG( "logs [ENG] <- LogsDbConnector::readCompleted()" ) |
|
507 } |
|
508 |
|
509 // ---------------------------------------------------------------------------- |
|
510 // LogsDbConnector::errorOccurred |
|
511 // ---------------------------------------------------------------------------- |
|
512 // |
|
513 void LogsDbConnector::errorOccurred(int err) |
|
514 { |
|
515 LOGS_QDEBUG_2( "logs [ENG] <-> LogsDbConnector::errorOccurred(), err:", err ) |
|
516 |
|
517 // TODO: error handling |
|
518 |
|
519 handleModifyingCompletion(err); |
|
520 |
|
521 Q_UNUSED(err) |
|
522 } |
|
523 |
|
524 // ---------------------------------------------------------------------------- |
|
525 // LogsDbConnector::temporaryErrorOccurred |
|
526 // ---------------------------------------------------------------------------- |
|
527 // |
|
528 void LogsDbConnector::temporaryErrorOccurred(int err) |
|
529 { |
|
530 LOGS_QDEBUG_2( |
|
531 "logs [ENG] -> LogsDbConnector::temporaryErrorOccurred(), err:", err ) |
|
532 |
|
533 handleTemporaryError(err); |
|
534 |
|
535 LOGS_QDEBUG( "logs [ENG] <- LogsDbConnector::temporaryErrorOccurred()" ) |
|
536 } |
|
537 |
|
538 // ---------------------------------------------------------------------------- |
|
539 // LogsDbConnector::eventModifyingCompleted |
|
540 // ---------------------------------------------------------------------------- |
|
541 // |
|
542 void LogsDbConnector::eventModifyingCompleted() |
|
543 { |
|
544 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::eventModifyingCompleted()" ) |
|
545 |
|
546 if ( handleModifyingCompletion() ){ |
|
547 // Possible to continue modifying |
|
548 int err = doMarkEventSeen(); |
|
549 if ( err != 0 ){ |
|
550 // But failed for some reason |
|
551 LOGS_QDEBUG( "logs [ENG] Couldn't continue modifying" ) |
|
552 handleModifyingCompletion(err); |
|
553 } |
|
554 } |
|
555 |
|
556 LOGS_QDEBUG( "logs [ENG] <- LogsDbConnector::eventModifyingCompleted()" ) |
|
557 } |
|
558 |
|
559 // ---------------------------------------------------------------------------- |
|
560 // LogsDbConnector::duplicatesReadingCompleted |
|
561 // ---------------------------------------------------------------------------- |
|
562 // |
|
563 void LogsDbConnector::duplicatesReadingCompleted(QList<LogsEvent*> duplicates) |
|
564 { |
|
565 LOGS_QDEBUG( "logs [ENG] -> LogsDbConnector::duplicatesReadingCompleted()" ) |
|
566 qDeleteAll( mDuplicatedEvents ); |
|
567 mDuplicatedEvents.clear(); |
|
568 mDuplicatedEvents = duplicates; |
|
569 emit duplicatesRead(); |
|
570 LOGS_QDEBUG( "logs [ENG] <- LogsDbConnector::duplicatesReadingCompleted()" ) |
|
571 } |
|
572 |
|
573 // ---------------------------------------------------------------------------- |
|
574 // LogsDbConnector::doMarkEventSeen |
|
575 // ---------------------------------------------------------------------------- |
|
576 // |
|
577 int LogsDbConnector::doMarkEventSeen() |
|
578 { |
|
579 int err = -1; |
|
580 if ( mEventsSeen.count() > 0 ){ |
|
581 err = mReader->markEventSeen(mEventsSeen.at(0)); |
|
582 } |
|
583 return err; |
|
584 } |
|
585 |
|
586 // ---------------------------------------------------------------------------- |
|
587 // LogsDbConnector::handleModifyingCompletion |
|
588 // ---------------------------------------------------------------------------- |
|
589 // |
|
590 bool LogsDbConnector::handleModifyingCompletion(int err) |
|
591 { |
|
592 bool continueModify( false ); |
|
593 if ( err || mEventsSeen.count() == 1 ){ |
|
594 mEventsSeen.clear(); |
|
595 emit markingCompleted(err); |
|
596 } else if ( mEventsSeen.count() > 1 ){ |
|
597 // Item was modified succesfully and more to modify, remove handled |
|
598 // item from queue |
|
599 mEventsSeen.takeFirst(); |
|
600 continueModify = true; |
|
601 } else { |
|
602 |
|
603 } |
|
604 return continueModify; |
|
605 } |