Merge pull request #26148 from ksooo/fix-secondstotimestring-warning
[xbmc.git] / xbmc / pictures / PictureFolderImageFileLoader.cpp
blob0370bc50d01081356ea787e3f69d5308a5647508
1 /*
2 * Copyright (C) 2023 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 "PictureFolderImageFileLoader.h"
11 #include "FileItem.h"
12 #include "FileItemList.h"
13 #include "Picture.h"
14 #include "ServiceBroker.h"
15 #include "TextureCache.h"
16 #include "filesystem/Directory.h"
17 #include "guilib/Texture.h"
18 #include "imagefiles/ImageFileURL.h"
19 #include "playlists/PlayListFileItemClassify.h"
20 #include "settings/Settings.h"
21 #include "settings/SettingsComponent.h"
22 #include "utils/FileExtensionProvider.h"
24 using namespace KODI;
25 using namespace XFILE;
27 bool CPictureFolderImageFileLoader::CanLoad(const std::string& specialType) const
29 return specialType == "picturefolder";
32 std::unique_ptr<CTexture> CPictureFolderImageFileLoader::Load(
33 const IMAGE_FILES::CImageFileURL& imageFile) const
35 CFileItemList imagesInFolder;
36 CDirectory::GetDirectory(imageFile.GetTargetFile(), imagesInFolder,
37 CServiceBroker::GetFileExtensionProvider().GetPictureExtensions(),
38 DIR_FLAG_NO_FILE_DIRS);
40 for (int i = 0; i < imagesInFolder.Size();)
42 if (!imagesInFolder[i]->IsPicture() || imagesInFolder[i]->IsZIP() ||
43 imagesInFolder[i]->IsRAR() || PLAYLIST::IsPlayList(*imagesInFolder[i]))
45 imagesInFolder.Remove(i);
47 else
48 i++;
50 if (imagesInFolder.IsEmpty())
52 return {};
55 imagesInFolder.Randomize();
56 std::vector<std::string> imagesToTile;
57 int size = std::min(4, imagesInFolder.Size());
58 imagesToTile.reserve(size);
59 for (int thumb = 0; thumb < size; thumb++)
61 imagesToTile.push_back(imagesInFolder[thumb]->GetPath());
64 return CPicture::CreateTiledThumb(imagesToTile);