--- a/logsui/logsengine/logssymbianos/src/logsremove.cpp Tue Jul 06 14:16:36 2010 +0300
+++ b/logsui/logsengine/logssymbianos/src/logsremove.cpp Wed Aug 18 09:49:12 2010 +0300
@@ -20,27 +20,24 @@
#include "logsmodel.h"
#include "logslogger.h"
#include "logsremoveobserver.h"
+#include "logsremovestates.h"
#include <logcli.h>
#include <f32file.h>
#include <logview.h>
//SYSTEM
// CONSTANTS
-_LIT( KMaxLogsTime, "99991130:235959.999999");
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
//
LogsRemove::LogsRemove( LogsRemoveObserver& observer, bool readingAllEvents )
-: CActive(EPriorityStandard),
+: LogsWorker(readingAllEvents),
mObserver(observer),
- mReadingAllEvents(readingAllEvents),
- mLogClient(0),
- mRecentView(0)
+ mFsSession(0),
+ mClearType(-1)
{
- CActiveScheduler::Add( this );
- mFsSession = new RFs();
}
// -----------------------------------------------------------------------------
@@ -49,45 +46,21 @@
//
LogsRemove::~LogsRemove()
{
- LOGS_QDEBUG( "logs [ENG] <-> LogsRemove::~LogsRemove()" )
+ LOGS_QDEBUG( "logs [ENG] -> LogsRemove::~LogsRemove()" )
Cancel();
- delete mRecentView;
+ delete mLogViewRecent;
+ mLogViewRecent = 0;
+ delete mDuplicatesView;
+ mDuplicatesView = 0;
delete mLogClient;
+ mLogClient = 0;
if ( mFsSession ){
mFsSession->Close();
}
delete mFsSession;
-}
-
-// ----------------------------------------------------------------------------
-// LogsRemove::RunL
-// ----------------------------------------------------------------------------
-//
-void LogsRemove::RunL()
-{
- LOGS_QDEBUG( "logs [ENG] -> LogsRemove::RunL()->" )
- if (iStatus.Int() == KErrNone){
- LOGS_QDEBUG( "logs [ENG] -> LogsRemove::RunL() KErrNone" )
- if ( !DeleteNextEvent() ){
- mObserver.removeCompleted();
- }
- }
- else {
- User::Leave( iStatus.Int() );
- LOGS_QDEBUG( "logs [ENG] -> LogsRemove::RunL() !KErrNone" )
- }
- LOGS_QDEBUG( "logs [ENG] <- LogsRemove::RunL()<-" )
-}
-
-// ----------------------------------------------------------------------------
-// LogsRemove::DoCancel
-// ----------------------------------------------------------------------------
-//
-void LogsRemove::DoCancel()
-{
- if ( mLogClient ){
- mLogClient->Cancel();
- }
+ qDeleteAll( mRemoveStates );
+ qDeleteAll( mClearAllStates );
+ LOGS_QDEBUG( "logs [ENG] <- LogsRemove::~LogsRemove()" )
}
// ----------------------------------------------------------------------------
@@ -120,39 +93,53 @@
//
bool LogsRemove::clearList(LogsModel::ClearType cleartype)
{
- LOGS_QDEBUG( "logs [ENG] <- LogsRemove::clearList->" )
- if ( init() != KErrNone ) {
- return false;
- }
- bool clearingStarted(false);
- TTime time( KMaxLogsTime );
- if ( !IsActive() ){
- if (cleartype == LogsModel::TypeLogsClearAll){
- mLogClient->ClearLog( time, iStatus );
- }
- else{
- mLogClient->ClearLog( cleartype, iStatus );
- }
- SetActive();
- clearingStarted = true;
- } else {
- }
+ LOGS_QDEBUG( "logs [ENG] -> LogsRemove::clearList" )
+
+ bool clearingStarted( false );
+ TRAP_IGNORE( clearingStarted = clearListL(cleartype) )
+
LOGS_QDEBUG_2( "logs [ENG] <- LogsRemove::clearList, started", clearingStarted )
return clearingStarted;
}
// ----------------------------------------------------------------------------
+// LogsRemove::clearListL
+// ----------------------------------------------------------------------------
+//
+bool LogsRemove::clearListL(LogsModel::ClearType cleartype)
+{
+ LOGS_QDEBUG( "logs [ENG] -> LogsRemove::clearListL" )
+
+ initializeClearAllL();
+
+ mClearType = cleartype;
+
+ bool clearingStarted = startClearingL();
+
+ LOGS_QDEBUG_2( "logs [ENG] <- LogsRemove::clearListL, started", clearingStarted )
+ return clearingStarted;
+}
+
+// ----------------------------------------------------------------------------
// LogsRemove::initL
// ----------------------------------------------------------------------------
//
void LogsRemove::initL()
{
- if ( mLogClient ){
- // Already initialized
- return;
+ LOGS_QDEBUG( "logs [ENG] -> LogsRemove::initL" )
+
+ __ASSERT_ALWAYS( !IsActive(), User::Leave( KErrInUse ) );
+
+ if ( !mFsSession ){
+ mFsSession = new (ELeave) RFs();
+ User::LeaveIfError( mFsSession->Connect() );
+ }
+
+ if ( !mLogClient ){
+ mLogClient = CLogClient::NewL( *mFsSession );
}
- User::LeaveIfError( mFsSession->Connect() );
- mLogClient = CLogClient::NewL( *mFsSession );
+
+ LOGS_QDEBUG( "logs [ENG] <- LogsRemove::initL" )
}
@@ -172,49 +159,117 @@
//
void LogsRemove::clearEventsL(const QList<int>& eventIds, bool& async)
{
- LOGS_QDEBUG( "logs [ENG] -> LogsRemove::clearEventL()")
+ LOGS_QDEBUG( "logs [ENG] -> LogsRemove::clearEventsL()")
+
+ async = false;
+ initializeIdBasedRemovalL();
+
+ mRemovedEvents = eventIds;
+ mCurrentEventId = eventIds.isEmpty() ? -1 : eventIds.at(0);
+ if ( !mRemovedEvents.isEmpty() ){
+ async = startClearingL();
+ }
+
+ LOGS_QDEBUG_2( "logs [ENG] <- LogsRemove::clearEventsL(): async", async )
+}
- async = false;
-
+// ----------------------------------------------------------------------------
+// LogsRemove::initializeClearAllL
+// ----------------------------------------------------------------------------
+//
+void LogsRemove::initializeClearAllL()
+{
initL();
- if ( mReadingAllEvents ){
- // When all events are read, recent view cannot be used for
- // event removal.
- Cancel();
- mRemovedEvents = eventIds;
- async = DeleteNextEvent();
- } else {
- if ( !mRecentView ) {
- mRecentView = CLogViewRecent::NewL( *mLogClient );
- }
- foreach( int currId, eventIds ){
- LOGS_QDEBUG_2( "logs [ENG] Removing, currid: ", currId )
- mRecentView->RemoveL( currId );
- }
- delete mRecentView;
- mRecentView = NULL;
+ if ( mClearAllStates.count() == 0 ){
+ LogsRemoveStateClearAll* clearAll = new LogsRemoveStateClearAll(*this, *this);
+ LogsRemoveStateDone* done = new LogsRemoveStateDone(*this, *this);
+ clearAll->setNextState(*done);
+ mClearAllStates.append(clearAll);
+ mClearAllStates.append(done);
}
-
- LOGS_QDEBUG_2( "logs [ENG] <- LogsRemove::clearEventL(): async", async )
+ mCurrentStateMachine = &mClearAllStates;
+ setCurrentState(*mClearAllStates.at(0));
}
// ----------------------------------------------------------------------------
-// LogsRemove::DeleteNextEvent
+// LogsRemove::initializeIdBasedRemovalL
+// ----------------------------------------------------------------------------
+//
+void LogsRemove::initializeIdBasedRemovalL()
+{
+ initL();
+
+ if ( !mLogViewRecent ){
+ mLogViewRecent = CLogViewRecent::NewL( *mLogClient );
+ }
+ if ( !mDuplicatesView ) {
+ mDuplicatesView = CLogViewDuplicate::NewL( *mLogClient );
+ }
+
+ if ( mRemoveStates.count() == 0 ){
+ LogsRemoveStateInit* init = new LogsRemoveStateInit(*this, *this);
+ LogsStateSearchingEvent* searchEvent = new LogsStateSearchingEvent(*this);
+ LogsRemoveStateDeleteDuplicates* deleteDuplicates =
+ new LogsRemoveStateDeleteDuplicates(*this, *this);
+ LogsRemoveStateDelete* deleteFromMain = new LogsRemoveStateDelete(*this, *this);
+ LogsRemoveStateDone* done = new LogsRemoveStateDone(*this, *this);
+ init->setNextState(*searchEvent);
+ searchEvent->setNextState(*deleteDuplicates);
+ deleteDuplicates->setNextState(*deleteFromMain);
+ deleteFromMain->setNextState(*done);
+ mRemoveStates.append(init);
+ mRemoveStates.append(searchEvent);
+ mRemoveStates.append(deleteDuplicates);
+ mRemoveStates.append(deleteFromMain);
+ mRemoveStates.append(done);
+ }
+ mCurrentStateMachine = &mRemoveStates;
+ setCurrentState(*mRemoveStates.at(0));
+}
+
+// ----------------------------------------------------------------------------
+// LogsRemove::startClearingL
// ----------------------------------------------------------------------------
//
-bool LogsRemove::DeleteNextEvent()
+bool LogsRemove::startClearingL()
+{
+ __ASSERT_ALWAYS( !IsActive(), User::Leave( KErrInUse ) );
+
+ if ( currentState().enterL() ){
+ SetActive();
+ return true;
+ }
+ return false;
+}
+
+// ----------------------------------------------------------------------------
+// LogsRemove::observer
+// ----------------------------------------------------------------------------
+//
+LogsRemoveObserver& LogsRemove::observer()
{
- bool deleting(false);
- if ( !mRemovedEvents.isEmpty() ){
- int currId = mRemovedEvents.takeFirst();
- LOGS_QDEBUG_2( "logs [ENG] LogsRemove::DeleteNextEvent, id: ", currId )
- mLogClient->DeleteEvent( currId, iStatus );
- SetActive();
- deleting = true;
- }
- return deleting;
+ return mObserver;
+}
+
+// ----------------------------------------------------------------------------
+// LogsRemove::removedEvents
+// ----------------------------------------------------------------------------
+//
+QList<int>& LogsRemove::removedEvents()
+{
+ return mRemovedEvents;
}
+// ----------------------------------------------------------------------------
+// LogsRemove::clearType
+// ----------------------------------------------------------------------------
+//
+int LogsRemove::clearType()
+{
+ return mClearType;
+}
+
+
// End of file