MCPcopy Create free account
hub / github.com/KangLin/RabbitRemoteControl / ImportFromJsonFile

Method ImportFromJsonFile

Src/Database/Database.cpp:369–407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

367}
368
369bool CDatabase::ImportFromJsonFile(const QString &szFile)
370{
371 bool bRet = false;
372 SetError();
373 QFile file(szFile);
374 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
375 SetError(tr("Failed to open import JSON file: %1; Error: %2").arg(szFile, file.errorString()));
376 qCritical(log) << GetError();
377 return false;
378 }
379
380 do {
381 QJsonDocument doc;
382 doc = QJsonDocument::fromJson(file.readAll());
383 if(!doc.isObject()) {
384 SetError(tr("Not a valid JSON file"));
385 qCritical(log) << GetError();
386 break;
387 }
388 auto root = doc.object();
389 QString szTitle = root["Title"].toString();
390 if(szTitle != "Rabbit Remote Control") {
391 SetError(tr("File format error. The title: \"%1\" is not \"Rabbit Remote Control\"").arg(szTitle));
392 qCritical(log) << GetError();
393 break;
394 }
395 QString szVersion = root["Version"].toString();
396 if(RabbitCommon::CTools::VersionCompare(szVersion, m_MinVersion) < 0) {
397 SetError(tr("The version is no longer supported: ")
398 + szVersion + " < " + m_MinVersion);
399 qCritical(log) << GetError();
400 break;
401 }
402 bRet = ImportFromJson(doc.object());
403 } while(0);
404
405 file.close();
406 return bRet;
407}
408
409bool CDatabase::ImportFromJson(const QJsonObject &obj)
410{

Callers 6

slotImportMethod · 0.80
foreachFunction · 0.80
slotImportMethod · 0.80
foreachFunction · 0.80
onImportBookmarksMethod · 0.80
importFromJsonMethod · 0.80

Calls 3

errorStringMethod · 0.80
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected