blob: 81b8cfac92e3f4636819e871bf4633b6d0adf5b0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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();
}
|