Audio plugin host https://kx.studio/carla
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.

juce_ContentSharer.h 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. namespace juce
  15. {
  16. /** A singleton class responsible for sharing content between apps and devices.
  17. You can share text, images, files or an arbitrary data block.
  18. @tags{GUI}
  19. */
  20. class JUCE_API ContentSharer : public DeletedAtShutdown
  21. {
  22. public:
  23. JUCE_DECLARE_SINGLETON (ContentSharer, false)
  24. /** Shares the given files. Each URL should be either a full file path
  25. or it should point to a resource within the application bundle. For
  26. resources on iOS it should be something like "content/image.png" if you
  27. want to specify a file from application bundle located in "content"
  28. directory. On Android you should specify only a filename, without an
  29. extension.
  30. Upon completion you will receive a callback with a sharing result. Note:
  31. Sadly on Android the returned success flag may be wrong as there is no
  32. standard way the sharing targets report if the sharing operation
  33. succeeded. Also, the optional error message is always empty on Android.
  34. */
  35. void shareFiles (const Array<URL>& files,
  36. std::function<void(bool /*success*/, const String& /*error*/)> callback);
  37. /** Shares the given text.
  38. Upon completion you will receive a callback with a sharing result. Note:
  39. Sadly on Android the returned success flag may be wrong as there is no
  40. standard way the sharing targets report if the sharing operation
  41. succeeded. Also, the optional error message is always empty on Android.
  42. */
  43. void shareText (const String& text,
  44. std::function<void(bool /*success*/, const String& /*error*/)> callback);
  45. /** A convenience function to share an image. This is useful when you have images
  46. loaded in memory. The images will be written to temporary files first, so if
  47. you have the images in question stored on disk already call shareFiles() instead.
  48. By default, images will be saved to PNG files, but you can supply a custom
  49. ImageFileFormat to override this. The custom file format will be owned and
  50. deleted by the sharer. e.g.
  51. @code
  52. Graphics g (myImage);
  53. g.setColour (Colours::green);
  54. g.fillEllipse (20, 20, 300, 200);
  55. Array<Image> images;
  56. images.add (myImage);
  57. ContentSharer::getInstance()->shareImages (images, myCallback);
  58. @endcode
  59. Upon completion you will receive a callback with a sharing result. Note:
  60. Sadly on Android the returned success flag may be wrong as there is no
  61. standard way the sharing targets report if the sharing operation
  62. succeeded. Also, the optional error message is always empty on Android.
  63. */
  64. void shareImages (const Array<Image>& images,
  65. std::function<void(bool /*success*/, const String& /*error*/)> callback,
  66. ImageFileFormat* imageFileFormatToUse = nullptr);
  67. /** A convenience function to share arbitrary data. The data will be written
  68. to a temporary file and then that file will be shared. If you have
  69. your data stored on disk already, call shareFiles() instead.
  70. Upon completion you will receive a callback with a sharing result. Note:
  71. Sadly on Android the returned success flag may be wrong as there is no
  72. standard way the sharing targets report if the sharing operation
  73. succeeded. Also, the optional error message is always empty on Android.
  74. */
  75. void shareData (const MemoryBlock& mb,
  76. std::function<void(bool /*success*/, const String& /*error*/)> callback);
  77. private:
  78. ContentSharer();
  79. ~ContentSharer();
  80. Array<File> temporaryFiles;
  81. std::function<void(bool, String)> callback;
  82. #if JUCE_CONTENT_SHARING
  83. struct Pimpl
  84. {
  85. virtual ~Pimpl() {}
  86. virtual void shareFiles (const Array<URL>& files) = 0;
  87. virtual void shareText (const String& text) = 0;
  88. };
  89. std::unique_ptr<Pimpl> pimpl;
  90. Pimpl* createPimpl();
  91. void startNewShare (std::function<void(bool, const String&)>);
  92. class ContentSharerNativeImpl;
  93. friend class ContentSharerNativeImpl;
  94. class PrepareImagesThread;
  95. friend class PrepareImagesThread;
  96. std::unique_ptr<PrepareImagesThread> prepareImagesThread;
  97. class PrepareDataThread;
  98. friend class PrepareDataThread;
  99. std::unique_ptr<PrepareDataThread> prepareDataThread;
  100. void filesToSharePrepared();
  101. #endif
  102. void deleteTemporaryFiles();
  103. void sharingFinished (bool, const String&);
  104. };
  105. } // namespace juce