file_location.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include <QtCore/QDateTime>
  9. class QFileInfo;
  10. namespace Platform {
  11. class FileBookmark;
  12. } // namespace Platform
  13. namespace Core {
  14. class ReadAccessEnabler {
  15. public:
  16. ReadAccessEnabler(const Platform::FileBookmark *bookmark);
  17. ReadAccessEnabler(
  18. const std::shared_ptr<Platform::FileBookmark> &bookmark);
  19. bool failed() const {
  20. return _failed;
  21. }
  22. ~ReadAccessEnabler();
  23. private:
  24. const Platform::FileBookmark *_bookmark = nullptr;
  25. bool _failed;
  26. };
  27. class FileLocation {
  28. public:
  29. FileLocation() = default;
  30. explicit FileLocation(const QString &name);
  31. explicit FileLocation(const QFileInfo &info);
  32. static FileLocation InMediaCacheLocation();
  33. [[nodiscard]] bool check() const;
  34. [[nodiscard]] const QString &name() const;
  35. void setBookmark(const QByteArray &bookmark);
  36. QByteArray bookmark() const;
  37. [[nodiscard]] bool isEmpty() const {
  38. return name().isEmpty();
  39. }
  40. [[nodiscard]] bool inMediaCache() const;
  41. bool accessEnable() const;
  42. void accessDisable() const;
  43. QString fname;
  44. QDateTime modified;
  45. qint64 size = 0;
  46. private:
  47. void resolveFromInfo(const QFileInfo &info);
  48. std::shared_ptr<Platform::FileBookmark> _bookmark;
  49. };
  50. inline bool operator==(const FileLocation &a, const FileLocation &b) {
  51. return (a.name() == b.name())
  52. && (a.modified == b.modified)
  53. && (a.size == b.size);
  54. }
  55. inline bool operator!=(const FileLocation &a, const FileLocation &b) {
  56. return !(a == b);
  57. }
  58. } // namespace Core