| 1 |
/* |
| 2 |
* Copyright (C) 2023 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 "PictureFolderImageFileLoader.h" |
| 10 |
|
| 11 |
#include "FileItem.h" |
| 12 |
#include "Picture.h" |
| 13 |
#include "ServiceBroker.h" |
| 14 |
#include "TextureCache.h" |
| 15 |
#include "filesystem/Directory.h" |
| 16 |
#include "guilib/Texture.h" |
| 17 |
#include "settings/Settings.h" |
| 18 |
#include "settings/SettingsComponent.h" |
| 19 |
#include "utils/FileExtensionProvider.h" |
| 20 |
|
| 21 |
using namespace XFILE; |
| 22 |
|
| 23 |
bool CPictureFolderImageFileLoader::CanLoad(const std::string& specialType) const |
| 24 |
{ |
| 25 |
return specialType == "picturefolder"; |
| 26 |
} |
| 27 |
|
| 28 |
std::unique_ptr<CTexture> CPictureFolderImageFileLoader::Load(const std::string& specialType, |
| 29 |
const std::string& filePath, |
| 30 |
unsigned int preferredWidth, |
| 31 |
unsigned int preferredHeight) const |
| 32 |
{ |
| 33 |
CFileItemList imagesInFolder; |
| 34 |
CDirectory::GetDirectory(filePath, imagesInFolder, |
| 35 |
CServiceBroker::GetFileExtensionProvider().GetPictureExtensions(), |
| 36 |
DIR_FLAG_NO_FILE_DIRS); |
| 37 |
|
| 38 |
for (int i = 0; i < imagesInFolder.Size();) |
| 39 |
{ |
| 40 |
if (!imagesInFolder[i]->IsPicture() || imagesInFolder[i]->IsZIP() || |
| 41 |
imagesInFolder[i]->IsRAR() || imagesInFolder[i]->IsPlayList()) |
| 42 |
{ |
| 43 |
imagesInFolder.Remove(i); |
| 44 |
} |
| 45 |
else |
| 46 |
i++; |
| 47 |
} |
| 48 |
if (imagesInFolder.IsEmpty()) |
| 49 |
{ |
| 50 |
return {}; |
| 51 |
} |
| 52 |
|
| 53 |
imagesInFolder.Randomize(); |
| 54 |
std::vector<std::string> imagesToTile; |
| 55 |
int size = std::min(4, imagesInFolder.Size()); |
| 56 |
imagesToTile.reserve(size); |
| 57 |
for (int thumb = 0; thumb < size; thumb++) |
| 58 |
{ |
| 59 |
imagesToTile.push_back(imagesInFolder[thumb]->GetPath()); |
| 60 |
} |
| 61 |
|
| 62 |
return CPicture::CreateTiledThumb(imagesToTile); |
| 63 |
} |