7 #ifndef _FCITX_UTILS_STANDARDPATH_H_ 8 #define _FCITX_UTILS_STANDARDPATH_H_ 27 #include <unordered_map> 29 #include <fcitx-utils/fcitxutils_export.h> 31 #include <fcitx-utils/macros.h> 41 template <
typename... Types>
47 bool operator()(
const std::string & ,
48 const std::string & ,
bool ) {
53 template <
typename First,
typename... Rest>
58 Chainer(First first, Rest... rest)
59 : super_class(std::move(rest)...), filter(std::move(first)) {}
61 bool operator()(
const std::string &path,
const std::string &dir,
63 if (!filter(path, dir, user)) {
66 return super_class::operator()(path, dir, user);
78 bool operator()(
const std::string &path,
const std::string &dir,
80 return !filter(path, dir, isUser);
93 struct FCITXUTILS_DEPRECATED_EXPORT
User {
94 bool operator()(
const std::string & ,
95 const std::string & ,
bool isUser) {
101 struct FCITXUTILS_DEPRECATED_EXPORT
Prefix {
102 Prefix(
const std::string &prefix_) : prefix(prefix_) {}
104 bool operator()(
const std::string &path,
const std::string & ,
113 struct FCITXUTILS_DEPRECATED_EXPORT
Suffix {
114 Suffix(
const std::string &suffix_) : suffix(suffix_) {}
116 bool operator()(
const std::string &path,
const std::string & ,
130 const std::string &tempPath = {})
131 : fd_(
UnixFD::own(fd)), path_(realFile), tempPath_(tempPath) {}
135 int fd()
const {
return fd_.fd(); }
136 bool isValid()
const {
return fd_.isValid(); }
138 const std::string &path()
const {
return path_; }
139 const std::string &tempPath()
const {
return tempPath_; }
148 std::string tempPath_;
162 int fd()
const {
return fd_.fd(); }
163 bool isValid()
const {
return fd_.isValid(); }
165 const std::string &path()
const {
return path_; }
176 using StandardPathFileMap = std::map<std::string, StandardPathFile>;
177 using StandardPathFilesMap =
178 std::map<std::string, std::vector<StandardPathFile>>;
211 const std::string &packageName,
212 const std::unordered_map<std::string, std::string> &builtInPath,
213 bool skipBuiltInPath,
bool skipUserPath);
215 explicit StandardPath(
bool skipFcitxPath,
bool skipUserPath);
230 static const char *fcitxPath(
const char *path);
234 static std::string fcitxPath(
const char *path,
const char *subPath);
239 void scanDirectories(
Type type,
240 const std::function<
bool(
const std::string &path,
241 bool user)> &scanner)
const;
247 void scanDirectories(
248 const std::string &userDir,
const std::vector<std::string> &directories,
249 const std::function<
bool(
const std::string &path,
bool user)> &scanner)
254 void scanFiles(
Type type,
const std::string &path,
255 const std::function<
bool(
const std::string &path,
256 const std::string &dir,
bool user)>
260 std::string userDirectory(
Type type)
const;
263 std::vector<std::string> directories(
Type type)
const;
266 std::string locate(
Type type,
const std::string &path)
const;
269 std::vector<std::string> locateAll(
Type type,
270 const std::string &path)
const;
293 const std::string &pathOrig)
const;
305 bool safeSave(
Type type,
const std::string &pathOrig,
306 const std::function<
bool(
int)> &callback)
const;
316 std::map<std::string, std::string>
317 locateWithFilter(
Type type,
const std::string &path,
318 std::function<
bool(
const std::string &path,
319 const std::string &dir,
bool user)>
331 template <
typename Arg1,
typename... Args>
332 std::map<std::string, std::string>
333 locate(
Type type,
const std::string &path, Arg1 arg1, Args... args)
const {
334 return locateWithFilter(type, path,
336 std::move(arg1), std::move(args)...));
340 std::vector<StandardPathFile> openAll(
Type type,
const std::string &path,
345 multiOpenFilter(
Type type,
const std::string &path,
int flags,
346 std::function<
bool(
const std::string &path,
347 const std::string &dir,
bool user)>
353 template <
typename... Args>
354 StandardPathFileMap
multiOpen(
Type type,
const std::string &path,
int flags,
355 Args... args)
const {
356 return multiOpenFilter(type, path, flags,
362 multiOpenAllFilter(
Type type,
const std::string &path,
int flags,
363 std::function<
bool(
const std::string &path,
364 const std::string &dir,
bool user)>
370 template <
typename... Args>
372 int flags, Args... args)
const {
373 return multiOpenAllFilter(type, path, flags,
377 int64_t timestamp(
Type type,
const std::string &path)
const;
387 static std::string findExecutable(
const std::string &name);
395 static bool hasExecutable(
const std::string &name);
404 void syncUmask()
const;
415 bool skipBuiltInPath()
const;
422 bool skipUserPath()
const;
425 std::unique_ptr<StandardPathPrivate> d_ptr;
431 builder <<
"StandardPathFile(fd=" << file.fd() <<
",path=" << file.path()
444 return StandardPathsType::Config;
446 return StandardPathsType::PkgConfig;
448 return StandardPathsType::Data;
450 return StandardPathsType::Cache;
452 return StandardPathsType::Runtime;
454 return StandardPathsType::Addon;
456 return StandardPathsType::PkgData;
458 return StandardPathsType::Config;
465 #endif // _FCITX_UTILS_STANDARDPATH_H_
Class wrap around the unix fd.
StandardPathsType
Enum for location type.
bool endsWith(std::string_view str, std::string_view suffix)
Check if a string ends with a suffix.
Filter class that filters based on user file.
Utility class that wraps around UnixFD.
Filter class to chain sub filters together.
Filter class that revert the sub filter result.
Filter class that filters file based on prefix.
Utility class to handle unix file decriptor.
New Utility classes to handle application specific path.
Filter class that filters file based on suffix.
static UnixFD own(int fd)
Create a UnixFD by owning the fd.
std::map< std::string, std::string > locate(Type type, const std::string &path, Arg1 arg1, Args... args) const
Locate all files match the filter under first [directory]/[path].
Utility class to open, locate, list files based on XDG standard.
bool startsWith(std::string_view str, std::string_view prefix)
Check if a string starts with a prefix.
StandardPathFilesMap multiOpenAll(Type type, const std::string &path, int flags, Args... args) const
Open all files match the filter under all [directory]/[path].
Type
Enum for location type.
StandardPathFileMap multiOpen(Type type, const std::string &path, int flags, Args... args) const
Open all files match the filter under first [directory]/[path].
addon shared library dir.
File descriptor wrapper that handles file descriptor and rename automatically.