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.
9 #include "PictureInfoLoader.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"
22 CPictureInfoLoader::CPictureInfoLoader()
24 m_mapFileItems
= new CFileItemList
;
28 CPictureInfoLoader::~CPictureInfoLoader()
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);
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
);
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
))
62 if (pItem
->HasPictureInfoTag())
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"));
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
))
86 if (pItem
->HasPictureInfoTag())
90 { // Nothing found, load tag from file
91 pItem
->GetPictureInfoTag()->Load(pItem
->GetPath());
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)