MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / getIcon

Method getIcon

launcher/ui/pages/modplatform/ResourceModel.cpp:318–360  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

316}
317
318std::optional<QIcon> ResourceModel::getIcon(QModelIndex& index, const QUrl& url)
319{
320 QPixmap pixmap;
321 if (QPixmapCache::find(url.toString(), &pixmap))
322 return { pixmap };
323
324 if (!m_current_icon_job) {
325 m_current_icon_job.reset(new NetJob("IconJob", APPLICATION->network()));
326 m_current_icon_job->setAskRetry(false);
327 }
328
329 if (m_currently_running_icon_actions.contains(url))
330 return {};
331 if (m_failed_icon_actions.contains(url))
332 return {};
333
334 auto cache_entry = APPLICATION->metacache()->resolveEntry(
335 metaEntryBase(),
336 QString("logos/%1").arg(QString(QCryptographicHash::hash(url.toEncoded(), QCryptographicHash::Algorithm::Sha1).toHex())));
337 auto icon_fetch_action = Net::ApiDownload::makeCached(url, cache_entry);
338
339 auto full_file_path = cache_entry->getFullPath();
340 connect(icon_fetch_action.get(), &Task::succeeded, this, [=] {
341 auto icon = QIcon(full_file_path);
342 QPixmapCache::insert(url.toString(), icon.pixmap(icon.actualSize({ 64, 64 })));
343
344 m_currently_running_icon_actions.remove(url);
345
346 emit dataChanged(index, index, { Qt::DecorationRole });
347 });
348 connect(icon_fetch_action.get(), &Task::failed, this, [=] {
349 m_currently_running_icon_actions.remove(url);
350 m_failed_icon_actions.insert(url);
351 });
352
353 m_currently_running_icon_actions.insert(url);
354
355 m_current_icon_job->addNetAction(icon_fetch_action);
356 if (!m_current_icon_job->isRunning())
357 QMetaObject::invokeMethod(m_current_icon_job.get(), &NetJob::start);
358
359 return {};
360}
361
362// No 'forgor to implement' shall pass here :blobfox_knife:
363#define NEED_FOR_CALLBACK_ASSERT(name) \

Callers 13

iconUpdatedMethod · 0.45
InstanceWindowMethod · 0.45
dataMethod · 0.45
iconMethod · 0.45
dataMethod · 0.45
CopyInstanceDialogMethod · 0.45
on_iconButton_clickedMethod · 0.45
NewInstanceDialogMethod · 0.45
setSuggestedPackMethod · 0.45
setSuggestedIconMethod · 0.45

Calls 15

QStringClass · 0.85
networkMethod · 0.80
setAskRetryMethod · 0.80
resolveEntryMethod · 0.80
metacacheMethod · 0.80
getFullPathMethod · 0.80
insertMethod · 0.80
addNetActionMethod · 0.80
metaEntryBaseFunction · 0.50
hashFunction · 0.50
toStringMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected