Merge pull request #26166 from ksooo/improve-plugin-ctx-menus
[xbmc.git] / xbmc / pictures / PictureInfoLoader.cpp
blob507834e5bd33808b4c4a959f3afdf6ecd955a96a
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "PictureInfoLoader.h"
11 #include "FileItem.h"
12 #include "FileItemList.h"
13 #include "PictureInfoTag.h"
14 #include "ServiceBroker.h"
15 #include "network/NetworkFileItemClassify.h"
16 #include "settings/Settings.h"
17 #include "settings/SettingsComponent.h"
18 #include "video/VideoFileItemClassify.h"
20 using namespace KODI;
22 CPictureInfoLoader::CPictureInfoLoader()
24 m_mapFileItems = new CFileItemList;
25 m_tagReads = 0;
28 CPictureInfoLoader::~CPictureInfoLoader()
30 StopThread();
31 delete m_mapFileItems;
34 void CPictureInfoLoader::OnLoaderStart()
36 // Load previously cached items from HD
37 m_mapFileItems->SetPath(m_pVecItems->GetPath());
38 m_mapFileItems->Load();
39 m_mapFileItems->SetFastLookup(true);
41 m_tagReads = 0;
42 m_loadTags = CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_PICTURES_USETAGS);
44 if (m_pProgressCallback)
45 m_pProgressCallback->SetProgressMax(m_pVecItems->GetFileCount());
48 bool CPictureInfoLoader::LoadItem(CFileItem* pItem)
50 bool result = LoadItemCached(pItem);
51 result |= LoadItemLookup(pItem);
53 return result;
56 bool CPictureInfoLoader::LoadItemCached(CFileItem* pItem)
58 if (!pItem->IsPicture() || pItem->IsZIP() || pItem->IsRAR() || pItem->IsCBR() || pItem->IsCBZ() ||
59 NETWORK::IsInternetStream(*pItem) || VIDEO::IsVideo(*pItem))
60 return false;
62 if (pItem->HasPictureInfoTag())
63 return true;
65 // Check the cached item
66 CFileItemPtr mapItem = (*m_mapFileItems)[pItem->GetPath()];
67 if (mapItem && mapItem->m_dateTime==pItem->m_dateTime && mapItem->HasPictureInfoTag())
68 { // Query map if we previously cached the file on HD
69 *pItem->GetPictureInfoTag() = *mapItem->GetPictureInfoTag();
70 pItem->SetArt("thumb", mapItem->GetArt("thumb"));
71 return true;
74 return true;
77 bool CPictureInfoLoader::LoadItemLookup(CFileItem* pItem)
79 if (m_pProgressCallback && !pItem->m_bIsFolder)
80 m_pProgressCallback->SetProgressAdvance();
82 if (!pItem->IsPicture() || pItem->IsZIP() || pItem->IsRAR() || pItem->IsCBR() || pItem->IsCBZ() ||
83 NETWORK::IsInternetStream(*pItem) || VIDEO::IsVideo(*pItem))
84 return false;
86 if (pItem->HasPictureInfoTag())
87 return false;
89 if (m_loadTags)
90 { // Nothing found, load tag from file
91 pItem->GetPictureInfoTag()->Load(pItem->GetPath());
92 m_tagReads++;
95 return true;
98 void CPictureInfoLoader::OnLoaderFinish()
100 // cleanup cache loaded from HD
101 m_mapFileItems->Clear();
103 // Save loaded items to HD
104 if (!m_bStop && m_tagReads > 0)
105 m_pVecItems->Save();