diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
commit | c04dcc2e7d834218ef2d4194331e383402495ae1 (patch) | |
tree | 7333e38d10d75386e60f336b80c2443c1166031d /xbmc/pictures/PictureInfoLoader.cpp | |
parent | Initial commit. (diff) | |
download | kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip |
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/pictures/PictureInfoLoader.cpp')
-rw-r--r-- | xbmc/pictures/PictureInfoLoader.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/xbmc/pictures/PictureInfoLoader.cpp b/xbmc/pictures/PictureInfoLoader.cpp new file mode 100644 index 0000000..81b8cfa --- /dev/null +++ b/xbmc/pictures/PictureInfoLoader.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "PictureInfoLoader.h" + +#include "FileItem.h" +#include "PictureInfoTag.h" +#include "ServiceBroker.h" +#include "settings/Settings.h" +#include "settings/SettingsComponent.h" + +CPictureInfoLoader::CPictureInfoLoader() +{ + m_mapFileItems = new CFileItemList; + m_tagReads = 0; +} + +CPictureInfoLoader::~CPictureInfoLoader() +{ + StopThread(); + delete m_mapFileItems; +} + +void CPictureInfoLoader::OnLoaderStart() +{ + // Load previously cached items from HD + m_mapFileItems->SetPath(m_pVecItems->GetPath()); + m_mapFileItems->Load(); + m_mapFileItems->SetFastLookup(true); + + m_tagReads = 0; + m_loadTags = CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_PICTURES_USETAGS); + + if (m_pProgressCallback) + m_pProgressCallback->SetProgressMax(m_pVecItems->GetFileCount()); +} + +bool CPictureInfoLoader::LoadItem(CFileItem* pItem) +{ + bool result = LoadItemCached(pItem); + result |= LoadItemLookup(pItem); + + return result; +} + +bool CPictureInfoLoader::LoadItemCached(CFileItem* pItem) +{ + if (!pItem->IsPicture() || pItem->IsZIP() || pItem->IsRAR() || pItem->IsCBR() || pItem->IsCBZ() || pItem->IsInternetStream() || pItem->IsVideo()) + return false; + + if (pItem->HasPictureInfoTag()) + return true; + + // Check the cached item + CFileItemPtr mapItem = (*m_mapFileItems)[pItem->GetPath()]; + if (mapItem && mapItem->m_dateTime==pItem->m_dateTime && mapItem->HasPictureInfoTag()) + { // Query map if we previously cached the file on HD + *pItem->GetPictureInfoTag() = *mapItem->GetPictureInfoTag(); + pItem->SetArt("thumb", mapItem->GetArt("thumb")); + return true; + } + + return true; +} + +bool CPictureInfoLoader::LoadItemLookup(CFileItem* pItem) +{ + if (m_pProgressCallback && !pItem->m_bIsFolder) + m_pProgressCallback->SetProgressAdvance(); + + if (!pItem->IsPicture() || pItem->IsZIP() || pItem->IsRAR() || pItem->IsCBR() || pItem->IsCBZ() || pItem->IsInternetStream() || pItem->IsVideo()) + return false; + + if (pItem->HasPictureInfoTag()) + return false; + + if (m_loadTags) + { // Nothing found, load tag from file + pItem->GetPictureInfoTag()->Load(pItem->GetPath()); + m_tagReads++; + } + + return true; +} + +void CPictureInfoLoader::OnLoaderFinish() +{ + // cleanup cache loaded from HD + m_mapFileItems->Clear(); + + // Save loaded items to HD + if (!m_bStop && m_tagReads > 0) + m_pVecItems->Save(); +} |