| 1 |
/* |
| 2 |
* Copyright (C) 2005-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "PictureInfoLoader.h" |
| 10 |
|
| 11 |
#include "FileItem.h" |
| 12 |
#include "PictureInfoTag.h" |
| 13 |
#include "ServiceBroker.h" |
| 14 |
#include "settings/Settings.h" |
| 15 |
#include "settings/SettingsComponent.h" |
| 16 |
|
| 17 |
CPictureInfoLoader::CPictureInfoLoader() |
| 18 |
{ |
| 19 |
m_mapFileItems = new CFileItemList; |
| 20 |
m_tagReads = 0; |
| 21 |
} |
| 22 |
|
| 23 |
CPictureInfoLoader::~CPictureInfoLoader() |
| 24 |
{ |
| 25 |
StopThread(); |
| 26 |
delete m_mapFileItems; |
| 27 |
} |
| 28 |
|
| 29 |
void CPictureInfoLoader::OnLoaderStart() |
| 30 |
{ |
| 31 |
// Load previously cached items from HD |
| 32 |
m_mapFileItems->SetPath(m_pVecItems->GetPath()); |
| 33 |
m_mapFileItems->Load(); |
| 34 |
m_mapFileItems->SetFastLookup(true); |
| 35 |
|
| 36 |
m_tagReads = 0; |
| 37 |
m_loadTags = CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_PICTURES_USETAGS); |
| 38 |
|
| 39 |
if (m_pProgressCallback) |
| 40 |
m_pProgressCallback->SetProgressMax(m_pVecItems->GetFileCount()); |
| 41 |
} |
| 42 |
|
| 43 |
bool CPictureInfoLoader::LoadItem(CFileItem* pItem) |
| 44 |
{ |
| 45 |
bool result = LoadItemCached(pItem); |
| 46 |
result |= LoadItemLookup(pItem); |
| 47 |
|
| 48 |
return result; |
| 49 |
} |
| 50 |
|
| 51 |
bool CPictureInfoLoader::LoadItemCached(CFileItem* pItem) |
| 52 |
{ |
| 53 |
if (!pItem->IsPicture() || pItem->IsZIP() || pItem->IsRAR() || pItem->IsCBR() || pItem->IsCBZ() || pItem->IsInternetStream() || pItem->IsVideo()) |
| 54 |
return false; |
| 55 |
|
| 56 |
if (pItem->HasPictureInfoTag()) |
| 57 |
return true; |
| 58 |
|
| 59 |
// Check the cached item |
| 60 |
CFileItemPtr mapItem = (*m_mapFileItems)[pItem->GetPath()]; |
| 61 |
if (mapItem && mapItem->m_dateTime==pItem->m_dateTime && mapItem->HasPictureInfoTag()) |
| 62 |
{ // Query map if we previously cached the file on HD |
| 63 |
*pItem->GetPictureInfoTag() = *mapItem->GetPictureInfoTag(); |
| 64 |
pItem->SetArt("thumb", mapItem->GetArt("thumb")); |
| 65 |
return true; |
| 66 |
} |
| 67 |
|
| 68 |
return true; |
| 69 |
} |
| 70 |
|
| 71 |
bool CPictureInfoLoader::LoadItemLookup(CFileItem* pItem) |
| 72 |
{ |
| 73 |
if (m_pProgressCallback && !pItem->m_bIsFolder) |
| 74 |
m_pProgressCallback->SetProgressAdvance(); |
| 75 |
|
| 76 |
if (!pItem->IsPicture() || pItem->IsZIP() || pItem->IsRAR() || pItem->IsCBR() || pItem->IsCBZ() || pItem->IsInternetStream() || pItem->IsVideo()) |
| 77 |
return false; |
| 78 |
|
| 79 |
if (pItem->HasPictureInfoTag()) |
| 80 |
return false; |
| 81 |
|
| 82 |
if (m_loadTags) |
| 83 |
{ // Nothing found, load tag from file |
| 84 |
pItem->GetPictureInfoTag()->Load(pItem->GetPath()); |
| 85 |
m_tagReads++; |
| 86 |
} |
| 87 |
|
| 88 |
return true; |
| 89 |
} |
| 90 |
|
| 91 |
void CPictureInfoLoader::OnLoaderFinish() |
| 92 |
{ |
| 93 |
// cleanup cache loaded from HD |
| 94 |
m_mapFileItems->Clear(); |
| 95 |
|
| 96 |
// Save loaded items to HD |
| 97 |
if (!m_bStop && m_tagReads > 0) |
| 98 |
m_pVecItems->Save(); |
| 99 |
} |