! Update document abstract from local cache. */
| 4315 | Update document abstract from local cache. |
| 4316 | */ |
| 4317 | bool WizDatabase::updateDocumentAbstract(const QString& strDocumentGUID) |
| 4318 | { |
| 4319 | CString strFileName = getDocumentFileName(strDocumentGUID); |
| 4320 | if (!WizPathFileExists(strFileName)) { |
| 4321 | return false; |
| 4322 | } |
| 4323 | |
| 4324 | WIZDOCUMENTDATA data; |
| 4325 | if (!documentFromGuid(strDocumentGUID, data)) { |
| 4326 | qDebug() << "[updateDocumentAbstract]invalide guid: " << strDocumentGUID; |
| 4327 | return false; |
| 4328 | } |
| 4329 | |
| 4330 | if (data.nProtected) |
| 4331 | emptyProtectedAbstract(strDocumentGUID); |
| 4332 | |
| 4333 | QString strTempFolder = Utils::WizPathResolve::tempPath() + data.strGUID + "-thumb/"; |
| 4334 | // delete folder to clear unused images. |
| 4335 | ::WizDeleteAllFilesInFolder(strTempFolder); |
| 4336 | if (!documentToHtmlFile(data, strTempFolder)) { |
| 4337 | qDebug() << "[updateDocumentAbstract]decompress to temp failed, guid: " |
| 4338 | << strDocumentGUID; |
| 4339 | return false; |
| 4340 | } |
| 4341 | CString strHtmlFileName = strTempFolder + "index.html"; |
| 4342 | |
| 4343 | CString strHtmlTempPath = Utils::WizMisc::extractFilePath(strHtmlFileName); |
| 4344 | |
| 4345 | CString strHtml; |
| 4346 | ::WizLoadUnicodeTextFromFile(strHtmlFileName, strHtml); |
| 4347 | |
| 4348 | WIZABSTRACT abstract; |
| 4349 | abstract.guid = strDocumentGUID; |
| 4350 | |
| 4351 | WizHtmlToPlainText htmlConverter; |
| 4352 | htmlConverter.toText(strHtml, abstract.text); |
| 4353 | abstract.text = abstract.text.left(2000); |
| 4354 | |
| 4355 | CString strResourcePath = Utils::WizMisc::extractFilePath(strHtmlFileName) + "index_files/"; |
| 4356 | CWizStdStringArray arrayImageFileName; |
| 4357 | ::WizEnumFiles(strResourcePath, "*.jpg;*.png;*.bmp;*.gif", arrayImageFileName, 0); |
| 4358 | if (!arrayImageFileName.empty()) |
| 4359 | { |
| 4360 | CString strImageFileName; |
| 4361 | |
| 4362 | qint64 m = 0; |
| 4363 | CWizStdStringArray::const_iterator it; |
| 4364 | for (it = arrayImageFileName.begin(); it != arrayImageFileName.end(); it++) { |
| 4365 | CString strFileName = *it; |
| 4366 | // |
| 4367 | QString name = Utils::WizMisc::extractFileName(strFileName); |
| 4368 | if (name.startsWith("wizIcon")) |
| 4369 | continue; |
| 4370 | if (name.startsWith("checked")) |
| 4371 | continue; |
| 4372 | if (name.startsWith("unchecked")) |
| 4373 | continue; |
| 4374 | // |
no test coverage detected