| 103 | } |
| 104 | |
| 105 | void Meta::BaseEntity::load(Net::Mode loadType) |
| 106 | { |
| 107 | // load local file if nothing is loaded yet |
| 108 | if(!isLoaded()) |
| 109 | { |
| 110 | if(loadLocalFile()) |
| 111 | { |
| 112 | m_loadStatus = LoadStatus::Local; |
| 113 | } |
| 114 | } |
| 115 | // if we need remote update, run the update task |
| 116 | if(loadType == Net::Mode::Offline || !shouldStartRemoteUpdate()) |
| 117 | { |
| 118 | return; |
| 119 | } |
| 120 | m_updateTask = new NetJob(QObject::tr("Download of meta file %1").arg(localFilename())); |
| 121 | auto url = this->url(); |
| 122 | auto entry = APPLICATION->metacache()->resolveEntry("meta", localFilename()); |
| 123 | entry->setStale(true); |
| 124 | auto dl = Net::Download::makeCached(url, entry); |
| 125 | /* |
| 126 | * The validator parses the file and loads it into the object. |
| 127 | * If that fails, the file is not written to storage. |
| 128 | */ |
| 129 | dl->addValidator(new ParsingValidator(this)); |
| 130 | m_updateTask->addNetAction(dl); |
| 131 | m_updateStatus = UpdateStatus::InProgress; |
| 132 | QObject::connect(m_updateTask.get(), &NetJob::succeeded, [&]() |
| 133 | { |
| 134 | m_loadStatus = LoadStatus::Remote; |
| 135 | m_updateStatus = UpdateStatus::Succeeded; |
| 136 | m_updateTask.reset(); |
| 137 | }); |
| 138 | QObject::connect(m_updateTask.get(), &NetJob::failed, [&]() |
| 139 | { |
| 140 | m_updateStatus = UpdateStatus::Failed; |
| 141 | m_updateTask.reset(); |
| 142 | }); |
| 143 | m_updateTask->start(APPLICATION->network()); |
| 144 | } |
| 145 | |
| 146 | bool Meta::BaseEntity::isLoaded() const |
| 147 | { |
no test coverage detected