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.5KB

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