| 365 | } |
| 366 | |
| 367 | bool CRecentDatabase::ImportFromJson(const QJsonObject &obj) |
| 368 | { |
| 369 | QJsonArray recents = obj["Recent"].toArray(); |
| 370 | if(recents.isEmpty()){ |
| 371 | SetError(tr("The file format is error. Don't find \"recents\"")); |
| 372 | qCritical(log) << GetError(); |
| 373 | return false; |
| 374 | } |
| 375 | |
| 376 | for(auto it = recents.begin(); it != recents.end(); it++) { |
| 377 | QJsonObject itemObj = it->toObject(); |
| 378 | RecentItem item; |
| 379 | |
| 380 | QString szFile; |
| 381 | bool bRet = m_FileDB.ImportFileToDatabaseFromJson(itemObj, szFile); |
| 382 | if(!bRet) continue; |
| 383 | |
| 384 | item.SetFile(szFile); |
| 385 | // Check if is exist in recent |
| 386 | QSqlQuery query(GetDatabase()); |
| 387 | query.prepare( |
| 388 | "SELECT id FROM recent " |
| 389 | "WHERE file=:file" |
| 390 | ); |
| 391 | query.bindValue(":file", item.szFile); |
| 392 | if (query.exec() && query.next()) { |
| 393 | continue; |
| 394 | } |
| 395 | |
| 396 | bRet = CDatabaseIcon::ImportIconFromJson(itemObj, item.icon); |
| 397 | if(!bRet) continue; |
| 398 | |
| 399 | item.szOperateId = itemObj["OperateId"].toString(); |
| 400 | item.szName = itemObj["Name"].toString(); |
| 401 | item.szProtocol = itemObj["Protocol"].toString(); |
| 402 | item.szType = itemObj["Type"].toString(); |
| 403 | |
| 404 | item.time = QDateTime::fromString(itemObj["Time"].toString()); |
| 405 | if(!item.time.isValid()) |
| 406 | item.time = QDateTime::currentDateTime(); |
| 407 | |
| 408 | item.szDescription = itemObj["Description"].toString(); |
| 409 | AddRecent(item); |
| 410 | } |
| 411 | return true; |
| 412 | } |
nothing calls this directly
no test coverage detected