Skip to content
Repos

DevPlaceApp

C++ 1.0 KB22 lines Opens in site

Directory Raw Download

#pragma once
// Spec: FR-MEDIA-01, FR-UP-01. Native open and save file dialogs (SDL_ShowOpenFileDialog, SDL_ShowSaveFileDialog).
// The SDL callbacks arrive on another thread; the results are marshalled to the UI thread with UiQueue.
#include <functional>
#include <optional>
#include <string>

namespace dp {

class AttachmentFileDialogs {
 public:
  // path is empty when the user cancelled or no dialog is available.
  // mediaOnly restricts the dialog to image and video extensions (Photo Library source).
  static void openFile(bool mediaOnly, std::function<void(const std::string& path)> done);
  static void saveFile(const std::string& defaultName, std::function<void(const std::string& path)> done);
  // Reads at most maxBytes; nullopt when missing, unreadable or larger.
  static std::optional<std::string> readFile(const std::string& path, std::size_t maxBytes);
  static bool writeFile(const std::string& path, const std::string& bytes);
  static std::string lastPathComponent(const std::string& path);
};

}  // namespace dp
39.4ms