17#include <osl/file.hxx>
28bool set_file_status(osl::FileStatus& status,
const OUString& file)
30 osl::DirectoryItem dirItem;
31 osl::FileBase::RC retvalGet = osl::DirectoryItem::get(file, dirItem);
32 if (retvalGet != osl::FileBase::E_None) {
33 SAL_WARN(
"vcl.app",
"Could not determine status for file '" << file <<
"'.");
36 osl::FileBase::RC retvalStatus = dirItem.getFileStatus(status);
37 if (retvalStatus != osl::FileBase::E_None) {
38 SAL_WARN(
"vcl.app",
"Could not determine status for file '" << file <<
"'.");
44OUString convert_to_absolute_path(
const OUString& path)
47 osl::FileBase::RC rc =
resolver.fetchFileStatus(path);
48 if (rc != osl::FileBase::E_None) {
49 SAL_WARN(
"vcl.app",
"Could not resolve path '" << path <<
"' to search for icon themes.");
50 if (rc == osl::FileBase::E_MULTIHOP)
52 throw std::runtime_error(
"Provided a recursive symlink to an icon theme directory that could not be resolved.");
55 return resolver.m_aStatus.getFileURL();
67 std::deque<OUString> aPaths;
76 for (
const auto& path : aPaths)
78 osl::FileStatus fileStatus(osl_FileStatus_Mask_Type);
79 bool couldSetFileStatus = set_file_status(fileStatus, path);
80 if (!couldSetFileStatus) {
84 if (!fileStatus.isDirectory()) {
85 SAL_INFO(
"vcl.app",
"Cannot search for icon themes in '"<< path <<
"'. It is not a directory.");
90 if (iconThemePaths.empty()) {
91 SAL_WARN(
"vcl.app",
"Could not find any icon themes in the provided directory ('" <<path<<
"'.");
94 for (
auto const& iconThemePath : iconThemePaths)
107 SAL_INFO(
"vcl.app",
"Found a file that seems to be an icon theme: '" << url <<
"'" );
111 "' with id '" << newTheme.
GetThemeId() <<
"'.");
115 std::vector<OUString>
118 std::vector<OUString> found;
119 SAL_INFO(
"vcl.app",
"Scanning directory '" << dir <<
" for icon themes.");
121 osl::Directory dirToScan(dir);
122 osl::FileBase::RC retvalOpen = dirToScan.open();
123 if (retvalOpen != osl::FileBase::E_None) {
127 osl::DirectoryItem directoryItem;
128 while (dirToScan.getNextItem(directoryItem) == osl::FileBase::E_None) {
129 osl::FileStatus status(osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileURL | osl_FileStatus_Mask_FileName);
130 osl::FileBase::RC retvalStatus = directoryItem.getFileStatus(status);
131 if (retvalStatus != osl::FileBase::E_None) {
135 OUString filename = convert_to_absolute_path(status.getFileURL());
139 found.push_back(filename);
149 SAL_INFO(
"vcl.app",
"File '" << filename <<
"' does not seem to be an icon theme.");
153 osl::FileStatus fileStatus(osl_FileStatus_Mask_Type);
154 bool couldSetFileStatus = set_file_status(fileStatus, filename);
155 if (!couldSetFileStatus) {
159 if (!fileStatus.isRegular()) {
171 std::shared_ptr<IconThemeScanner>
175 retval->ScanDirectoryForIconThemes(path);
193 explicit SameTheme(
const OUString &rThemeId) :
m_rThemeId(rThemeId) {}
207 SAL_WARN(
"vcl.app",
"Requested information for icon theme with id '" << themeId
208 <<
"' which does not exist.");
209 throw std::runtime_error(
"Requested information on not-installed icon theme");
const OUString & m_rThemeId
const OUString & GetIconsetPath() const
This class provides information about an icon theme.
static bool UrlCanBeParsed(std::u16string_view url)
Check whether an IconThemeInfo can be constructed from a URL.
const OUString & GetThemeId() const
const OUString & GetDisplayName() const
static bool IconThemeIsInVector(const std::vector< vcl::IconThemeInfo > &themes, const OUString &themeId)
Check whether a theme with a specified id is in a vector of IconThemeInfo.
This class scans a folder for icon themes and provides the results.
const IconThemeInfo & GetIconThemeInfo(const OUString &themeId)
Get the IconThemeInfo for a theme.
static OUString GetStandardIconThemePath()
This method will return the standard path where icon themes are located.
bool AddIconThemeByPath(const OUString &path)
Adds the provided icon theme by path.
static std::vector< OUString > ReadIconThemesFromPath(const OUString &dir)
Scans the provided directory for icon themes.
std::vector< IconThemeInfo > mFoundIconThemes
bool IconThemeIsInstalled(const OUString &themeId) const
Checks whether the theme with the provided name has been found in the scanned directory.
void ScanDirectoryForIconThemes(std::u16string_view path)
Scan a directory for icon themes.
static bool FileIsValidIconTheme(const OUString &)
Check whether a single file is valid.
static std::shared_ptr< IconThemeScanner > Create(std::u16string_view path)
Factory method to create the object.
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)