#include "TaskFinishParsing.h" #include "DialogView.h" #include "PersistentStorage.h" #include "MessageIndexingFinished.h" #include "MessageIndexingStatus.h" #include "MessageQuitApplication.h" #include "MessageStatus.h" #include "Blackboard.h" #include "utility.h" #include "utilityString.h" #include "Application.h" TaskFinishParsing::TaskFinishParsing(std::shared_ptr storage, std::shared_ptr dialogView) : m_storage(storage) , m_dialogView(dialogView) { } void TaskFinishParsing::terminate() { m_dialogView->clearDialogs(); MessageStatus(L"An unknown exception was thrown during indexing.", true, false).dispatch(); MessageIndexingFinished().dispatch(); } void TaskFinishParsing::doEnter(std::shared_ptr blackboard) { m_storage->setMode(SqliteIndexStorage::STORAGE_MODE_READ); } Task::TaskState TaskFinishParsing::doUpdate(std::shared_ptr blackboard) { TimeStamp start = utility::durationStart(); m_dialogView->showUnknownProgressDialog(L"Finish Indexing", L"Optimizing database"); m_storage->optimizeMemory(); m_dialogView->hideUnknownProgressDialog(); float time = utility::duration(start); if (blackboard->exists("clear_time")) { float clearTime = 0; blackboard->get("clear_time", clearTime); time += clearTime; } if (blackboard->exists("index_time")) { float indexTime = 0; blackboard->get("index_time", indexTime); time += indexTime; } int indexedSourceFileCount = 0; blackboard->get("indexed_source_file_count", indexedSourceFileCount); int sourceFileCount = 0; blackboard->get("source_file_count", sourceFileCount); bool interruptedIndexing = false; blackboard->get("interrupted_indexing", interruptedIndexing); ErrorCountInfo errorInfo = m_storage->getErrorCount(); std::wstring status; status += L"Finished indexing: "; status += std::to_wstring(indexedSourceFileCount) + L"/" + std::to_wstring(sourceFileCount) + L" source files indexed; "; status += utility::decodeFromUtf8(utility::timeToString(time)); status += L"; " + std::to_wstring(errorInfo.total) + L" error" + (errorInfo.total != 1 ? L"s" : L""); if (errorInfo.fatal > 0) { status += L" (" + std::to_wstring(errorInfo.fatal) + L" fatal)"; } MessageStatus(status, false, false).dispatch(); StorageStats stats = m_storage->getStorageStats(); DatabasePolicy policy = m_dialogView->finishedIndexingDialog( indexedSourceFileCount, sourceFileCount, stats.completedFileCount, stats.fileCount, time, errorInfo, interruptedIndexing ); MessageIndexingStatus(false).dispatch(); if (policy == DATABASE_POLICY_KEEP) { blackboard->set("keep_database", true); } else if (policy == DATABASE_POLICY_DISCARD) { blackboard->set("discard_database", true); } return STATE_SUCCESS; } void TaskFinishParsing::doExit(std::shared_ptr blackboard) { m_storage.reset(); } void TaskFinishParsing::doReset(std::shared_ptr blackboard) { }