|
9 | 9 |
|
10 | 10 | #include <sal/config.h>
|
11 | 11 | #include <sal/log.hxx>
|
12 |
| - |
13 |
| -#include <deque> |
14 |
| - |
15 | 12 | #include <IconThemeScanner.hxx>
|
16 | 13 |
|
17 |
| -#include <osl/file.hxx> |
18 | 14 | #include <salhelper/linkhelper.hxx>
|
19 | 15 | #include <unotools/pathoptions.hxx>
|
20 | 16 | #include <vcl/IconThemeInfo.hxx>
|
21 | 17 | #include <o3tl/string_view.hxx>
|
22 | 18 |
|
23 |
| -namespace vcl { |
24 |
| - |
25 |
| -namespace { |
26 |
| - |
27 |
| -// set the status of a file. Returns false if the status could not be determined. |
28 |
| -bool set_file_status(osl::FileStatus& status, const OUString& file) |
| 19 | +namespace vcl |
29 | 20 | {
|
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 << "'."); |
34 |
| - return false; |
35 |
| - } |
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 << "'."); |
39 |
| - return false; |
40 |
| - } |
41 |
| - return true; |
42 |
| -} |
43 |
| - |
44 |
| -OUString convert_to_absolute_path(const OUString& path) |
45 |
| -{ |
46 |
| - salhelper::LinkResolver resolver(0); |
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) |
51 |
| - { |
52 |
| - throw std::runtime_error("Provided a recursive symlink to an icon theme directory that could not be resolved."); |
53 |
| - } |
54 |
| - } |
55 |
| - return resolver.m_aStatus.getFileURL(); |
56 |
| -} |
57 |
| - |
58 |
| -} |
59 | 21 |
|
60 | 22 | IconThemeScanner::IconThemeScanner() = default;
|
61 | 23 |
|
62 |
| -IconThemeScanner::IconThemeScanner(std::u16string_view paths) |
63 |
| -{ |
64 |
| - mFoundIconThemes.clear(); |
65 |
| - |
66 |
| - std::deque<OUString> aPaths; |
67 |
| - |
68 |
| - sal_Int32 nIndex = 0; |
69 |
| - do |
70 |
| - { |
71 |
| - aPaths.push_front(OUString(o3tl::getToken(paths, 0, ';', nIndex))); |
72 |
| - } |
73 |
| - while (nIndex >= 0); |
74 |
| - |
75 |
| - for (const auto& path : aPaths) |
76 |
| - { |
77 |
| - osl::FileStatus fileStatus(osl_FileStatus_Mask_Type); |
78 |
| - bool couldSetFileStatus = set_file_status(fileStatus, path); |
79 |
| - if (!couldSetFileStatus) { |
80 |
| - continue; |
81 |
| - } |
82 |
| - |
83 |
| - if (!fileStatus.isDirectory()) { |
84 |
| - SAL_INFO("vcl.app", "Cannot search for icon themes in '"<< path << "'. It is not a directory."); |
85 |
| - continue; |
86 |
| - } |
87 |
| - |
88 |
| - std::vector<OUString> iconThemePaths = ReadIconThemesFromPath(path); |
89 |
| - if (iconThemePaths.empty()) { |
90 |
| - SAL_WARN("vcl.app", "Could not find any icon themes in the provided directory ('" <<path<<"'."); |
91 |
| - continue; |
92 |
| - } |
93 |
| - for (auto const& iconThemePath : iconThemePaths) |
94 |
| - { |
95 |
| - AddIconThemeByPath(iconThemePath); |
96 |
| - } |
97 |
| - } |
98 |
| -} |
99 |
| - |
100 |
| -bool |
101 |
| -IconThemeScanner::AddIconThemeByPath(const OUString &url) |
| 24 | +bool IconThemeScanner::addResource(const OUString& rURL) |
102 | 25 | {
|
103 |
| - if (!IconThemeInfo::UrlCanBeParsed(url)) { |
| 26 | + if (!IconThemeInfo::UrlCanBeParsed(rURL)) { |
104 | 27 | return false;
|
105 | 28 | }
|
106 |
| - SAL_INFO("vcl.app", "Found a file that seems to be an icon theme: '" << url << "'" ); |
107 |
| - IconThemeInfo newTheme(url); |
| 29 | + SAL_INFO("vcl.app", "Found a file that seems to be an icon theme: '" << rURL << "'" ); |
| 30 | + IconThemeInfo newTheme(rURL); |
108 | 31 | mFoundIconThemes.push_back(newTheme);
|
109 | 32 | SAL_INFO("vcl.app", "Adding the file as '" << newTheme.GetDisplayName() <<
|
110 | 33 | "' with id '" << newTheme.GetThemeId() << "'.");
|
111 | 34 | return true;
|
112 | 35 | }
|
113 | 36 |
|
114 |
| -/*static*/ std::vector<OUString> |
115 |
| -IconThemeScanner::ReadIconThemesFromPath(const OUString& dir) |
116 |
| -{ |
117 |
| - std::vector<OUString> found; |
118 |
| - SAL_INFO("vcl.app", "Scanning directory '" << dir << " for icon themes."); |
119 |
| - |
120 |
| - osl::Directory dirToScan(dir); |
121 |
| - osl::FileBase::RC retvalOpen = dirToScan.open(); |
122 |
| - if (retvalOpen != osl::FileBase::E_None) { |
123 |
| - return found; |
124 |
| - } |
125 |
| - |
126 |
| - osl::DirectoryItem directoryItem; |
127 |
| - while (dirToScan.getNextItem(directoryItem) == osl::FileBase::E_None) { |
128 |
| - osl::FileStatus status(osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileURL | osl_FileStatus_Mask_FileName); |
129 |
| - osl::FileBase::RC retvalStatus = directoryItem.getFileStatus(status); |
130 |
| - if (retvalStatus != osl::FileBase::E_None) { |
131 |
| - continue; |
132 |
| - } |
133 |
| - |
134 |
| - OUString filename = convert_to_absolute_path(status.getFileURL()); |
135 |
| - if (!FileIsValidIconTheme(filename)) { |
136 |
| - continue; |
137 |
| - } |
138 |
| - found.push_back(filename); |
139 |
| - } |
140 |
| - return found; |
141 |
| -} |
142 |
| - |
143 |
| -/*static*/ bool |
144 |
| -IconThemeScanner::FileIsValidIconTheme(const OUString& filename) |
| 37 | +bool IconThemeScanner::isValidResource(const OUString& filename) |
145 | 38 | {
|
146 | 39 | // check whether we can construct an IconThemeInfo from it
|
147 |
| - if (!IconThemeInfo::UrlCanBeParsed(filename)) { |
| 40 | + if (!IconThemeInfo::UrlCanBeParsed(filename)) |
| 41 | + { |
148 | 42 | SAL_INFO("vcl.app", "File '" << filename << "' does not seem to be an icon theme.");
|
149 | 43 | return false;
|
150 | 44 | }
|
151 | 45 |
|
152 | 46 | osl::FileStatus fileStatus(osl_FileStatus_Mask_Type);
|
153 |
| - bool couldSetFileStatus = set_file_status(fileStatus, filename); |
154 |
| - if (!couldSetFileStatus) { |
| 47 | + if (!vcl::file::readFileStatus(fileStatus, filename)) |
155 | 48 | return false;
|
156 |
| - } |
157 | 49 |
|
158 |
| - if (!fileStatus.isRegular()) { |
| 50 | + if (!fileStatus.isRegular()) |
159 | 51 | return false;
|
160 |
| - } |
| 52 | + |
161 | 53 | return true;
|
162 | 54 | }
|
163 | 55 |
|
|
0 commit comments