The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
6.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. Functions that allow sharing content between apps and devices.
  23. You can share text, images, files or an arbitrary data block.
  24. @tags{GUI}
  25. */
  26. class JUCE_API ContentSharer
  27. {
  28. public:
  29. ContentSharer() = delete;
  30. /** A callback of this type is passed when starting a content sharing
  31. session.
  32. When the session ends, the function will receive a flag indicating
  33. whether the session was successful. In the case of failure, the
  34. errorText argument may hold a string describing the problem.
  35. */
  36. using Callback = std::function<void (bool success, const String& errorText)>;
  37. /** Shares the given files. Each URL should be either a full file path
  38. or it should point to a resource within the application bundle. For
  39. resources on iOS it should be something like "content/image.png" if you
  40. want to specify a file from application bundle located in "content"
  41. directory. On Android you should specify only a filename, without an
  42. extension.
  43. Upon completion you will receive a callback with a sharing result. Note:
  44. Sadly on Android the returned success flag may be wrong as there is no
  45. standard way the sharing targets report if the sharing operation
  46. succeeded. Also, the optional error message is always empty on Android.
  47. @param files the files to share
  48. @param callback a callback that will be called on the main thread
  49. when the sharing session ends
  50. @param parent the component that should be used to host the
  51. sharing view
  52. */
  53. [[nodiscard]] static ScopedMessageBox shareFilesScoped (const Array<URL>& files,
  54. Callback callback,
  55. Component* parent = nullptr);
  56. /** Shares the given text.
  57. Upon completion you will receive a callback with a sharing result. Note:
  58. Sadly on Android the returned success flag may be wrong as there is no
  59. standard way the sharing targets report if the sharing operation
  60. succeeded. Also, the optional error message is always empty on Android.
  61. @param text the text to share
  62. @param callback a callback that will be called on the main thread
  63. when the sharing session ends
  64. @param parent the component that should be used to host the
  65. sharing view
  66. */
  67. [[nodiscard]] static ScopedMessageBox shareTextScoped (const String& text,
  68. Callback callback,
  69. Component* parent = nullptr);
  70. /** A convenience function to share an image. This is useful when you have images
  71. loaded in memory. The images will be written to temporary files first, so if
  72. you have the images in question stored on disk already call shareFiles() instead.
  73. By default, images will be saved to PNG files, but you can supply a custom
  74. ImageFileFormat to override this. The custom file format will be owned and
  75. deleted by the sharer. e.g.
  76. @code
  77. Graphics g (myImage);
  78. g.setColour (Colours::green);
  79. g.fillEllipse (20, 20, 300, 200);
  80. Array<Image> images;
  81. images.add (myImage);
  82. ContentSharer::getInstance()->shareImages (images, myCallback);
  83. @endcode
  84. Upon completion you will receive a callback with a sharing result. Note:
  85. Sadly on Android the returned success flag may be wrong as there is no
  86. standard way the sharing targets report if the sharing operation
  87. succeeded. Also, the optional error message is always empty on Android.
  88. @param images the images to share
  89. @param format the file format to use when saving the images.
  90. If no format is provided, a sensible default will
  91. be used.
  92. @param callback a callback that will be called on the main thread
  93. when the sharing session ends
  94. @param parent the component that should be used to host the
  95. sharing view
  96. */
  97. [[nodiscard]] static ScopedMessageBox shareImagesScoped (const Array<Image>& images,
  98. std::unique_ptr<ImageFileFormat> format,
  99. Callback callback,
  100. Component* parent = nullptr);
  101. /** A convenience function to share arbitrary data. The data will be written
  102. to a temporary file and then that file will be shared. If you have
  103. your data stored on disk already, call shareFiles() instead.
  104. Upon completion you will receive a callback with a sharing result. Note:
  105. Sadly on Android the returned success flag may be wrong as there is no
  106. standard way the sharing targets report if the sharing operation
  107. succeeded. Also, the optional error message is always empty on Android.
  108. @param mb the data to share
  109. @param callback a callback that will be called on the main thread
  110. when the sharing session ends
  111. @param parent the component that should be used to host the
  112. sharing view
  113. */
  114. [[nodiscard]] static ScopedMessageBox shareDataScoped (const MemoryBlock& mb,
  115. Callback callback,
  116. Component* parent = nullptr);
  117. };
  118. } // namespace juce