2 * Copyright (C) 2024 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 "ImageFileURL.h"
12 #include "utils/URIUtils.h"
19 CImageFileURL::CImageFileURL(const std::string
& imageFileURL
)
21 if (!URIUtils::IsProtocol(imageFileURL
, "image"))
23 m_filePath
= imageFileURL
;
27 CURL url
{imageFileURL
};
28 m_filePath
= url
.GetHostName();
29 m_specialType
= url
.GetUserName();
31 url
.GetOptions(m_options
);
33 auto option
= m_options
.find("flipped");
34 if (option
!= m_options
.end())
37 m_options
.erase(option
);
41 CImageFileURL::CImageFileURL()
45 CImageFileURL
CImageFileURL::FromFile(const std::string
& filePath
, std::string specialType
)
47 if (URIUtils::IsProtocol(filePath
, "image"))
49 // this function should not be called with an image file URL
50 return CImageFileURL(filePath
);
54 item
.m_filePath
= filePath
;
55 item
.m_specialType
= std::move(specialType
);
60 void CImageFileURL::AddOption(std::string key
, std::string value
)
62 m_options
[std::move(key
)] = std::move(value
);
65 std::string
CImageFileURL::GetOption(const std::string
& key
) const
67 auto value
= m_options
.find(key
);
68 if (value
== m_options
.end())
75 std::string
CImageFileURL::ToString() const
78 url
.SetProtocol("image");
79 url
.SetUserName(m_specialType
);
80 url
.SetHostName(m_filePath
);
82 url
.SetOption("flipped", "");
83 for (const auto& option
: m_options
)
84 url
.SetOption(option
.first
, option
.second
);
89 std::string
CImageFileURL::ToCacheKey() const
91 if (!flipped
&& m_specialType
.empty() && m_options
.empty())
97 std::string
URLFromFile(const std::string
& filePath
, std::string specialType
)
99 return CImageFileURL::FromFile(filePath
, std::move(specialType
)).ToString();
102 std::string
ToCacheKey(const std::string
& imageFileURL
)
104 return CImageFileURL(imageFileURL
).ToCacheKey();
107 } // namespace IMAGE_FILES