file_utilities.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. namespace Main {
  9. class Session;
  10. } // namespace Main
  11. // legacy
  12. bool filedialogGetSaveFile(
  13. QString &file,
  14. const QString &caption,
  15. const QString &filter,
  16. const QString &initialPath);
  17. QString filedialogDefaultName(
  18. const QString &prefix,
  19. const QString &extension,
  20. const QString &path = QString(),
  21. bool skipExistance = false,
  22. TimeId fileTime = TimeId(0));
  23. QString filedialogNextFilename(
  24. const QString &name,
  25. const QString &cur,
  26. const QString &path = QString());
  27. namespace File {
  28. // Those functions are async wrappers to Platform::File::Unsafe* calls.
  29. void OpenUrl(const QString &url);
  30. void OpenEmailLink(const QString &email);
  31. void OpenWith(const QString &filepath);
  32. void Launch(const QString &filepath);
  33. void ShowInFolder(const QString &filepath);
  34. [[nodiscard]] QString DefaultDownloadPathFolder(
  35. not_null<Main::Session*> session);
  36. [[nodiscard]] QString DefaultDownloadPath(not_null<Main::Session*> session);
  37. namespace internal {
  38. inline QString UrlToLocalDefault(const QUrl &url) {
  39. return url.toLocalFile();
  40. }
  41. void UnsafeOpenUrlDefault(const QString &url);
  42. void UnsafeOpenEmailLinkDefault(const QString &email);
  43. void UnsafeLaunchDefault(const QString &filepath);
  44. } // namespace internal
  45. } // namespace File
  46. namespace FileDialog {
  47. struct OpenResult {
  48. QStringList paths;
  49. QByteArray remoteContent;
  50. };
  51. void GetOpenPath(
  52. QPointer<QWidget> parent,
  53. const QString &caption,
  54. const QString &filter,
  55. Fn<void(OpenResult &&result)> callback,
  56. Fn<void()> failed = Fn<void()>());
  57. void GetOpenPaths(
  58. QPointer<QWidget> parent,
  59. const QString &caption,
  60. const QString &filter,
  61. Fn<void(OpenResult &&result)> callback,
  62. Fn<void()> failed = Fn<void()>());
  63. void GetWritePath(
  64. QPointer<QWidget> parent,
  65. const QString &caption,
  66. const QString &filter,
  67. const QString &initialPath,
  68. Fn<void(QString &&result)> callback,
  69. Fn<void()> failed = Fn<void()>());
  70. void GetFolder(
  71. QPointer<QWidget> parent,
  72. const QString &caption,
  73. const QString &initialPath,
  74. Fn<void(QString &&result)> callback,
  75. Fn<void()> failed = Fn<void()>());
  76. [[nodiscard]] QString AllFilesFilter();
  77. [[nodiscard]] QString ImagesFilter();
  78. [[nodiscard]] QString AllOrImagesFilter();
  79. [[nodiscard]] QString ImagesOrAllFilter();
  80. [[nodiscard]] QString PhotoVideoFilesFilter();
  81. [[nodiscard]] const QString &Tmp();
  82. namespace internal {
  83. enum class Type {
  84. ReadFile,
  85. ReadFiles,
  86. ReadFolder,
  87. WriteFile,
  88. };
  89. void InitLastPathDefault();
  90. bool GetDefault(
  91. QPointer<QWidget> parent,
  92. QStringList &files,
  93. QByteArray &remoteContent,
  94. const QString &caption,
  95. const QString &filter,
  96. ::FileDialog::internal::Type type,
  97. QString startFile);
  98. } // namespace internal
  99. } // namespace FileDialog