PathUtil.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef PATHUTIL_H
  2. #define PATHUTIL_H
  3. #include "lmms_export.h"
  4. #include <QDir>
  5. namespace PathUtil
  6. {
  7. enum class Base { Absolute, ProjectDir, FactorySample, UserSample, UserVST, Preset,
  8. UserLADSPA, DefaultLADSPA, UserSoundfont, DefaultSoundfont, UserGIG, DefaultGIG,
  9. LocalDir };
  10. //! Return the directory associated with a given base as a QString
  11. //! Optionally, if a pointer to boolean is given the method will
  12. //! use it to indicate whether the prefix could be resolved properly
  13. //! or not.
  14. QString LMMS_EXPORT baseLocation(const Base base, bool* error = nullptr);
  15. //! Return the directory associated with a given base as a QDir.
  16. //! Optional pointer to boolean to indicate if the prefix could
  17. //! be resolved properly.
  18. QDir LMMS_EXPORT baseQDir (const Base base, bool* error = nullptr);
  19. //! Return the prefix used to denote this base in path strings
  20. QString LMMS_EXPORT basePrefix(const Base base);
  21. //! Check the prefix of a path and return the base it corresponds to
  22. //! Defaults to Base::Absolute
  23. Base LMMS_EXPORT baseLookup(const QString & path);
  24. //! Remove the prefix from a path, iff there is one
  25. QString LMMS_EXPORT stripPrefix(const QString & path);
  26. //! Get the filename for a path, handling prefixed paths correctly
  27. QString LMMS_EXPORT cleanName(const QString & path);
  28. //! Upgrade prefix-less relative paths to the new format
  29. QString LMMS_EXPORT oldRelativeUpgrade(const QString & input);
  30. //! Make this path absolute. If a pointer to boolean is given
  31. //! it will indicate whether the path was converted successfully
  32. QString LMMS_EXPORT toAbsolute(const QString & input, bool* error = nullptr);
  33. //! Make this path relative to a given base, return an absolute path if that fails
  34. QString LMMS_EXPORT relativeOrAbsolute(const QString & input, const Base base);
  35. //! Make this path relative to any base, choosing the shortest if there are
  36. //! multiple options. allowLocal defines whether local paths should be considered.
  37. //! Defaults to an absolute path if all bases fail.
  38. QString LMMS_EXPORT toShortestRelative(const QString & input, bool allowLocal = false);
  39. }
  40. #endif