29#if JUCE_CONTENT_SHARING
31class ContentSharer::PrepareImagesThread :
private Thread
34 PrepareImagesThread (ContentSharer& cs,
const Array<Image>& imagesToUse,
35 ImageFileFormat* imageFileFormatToUse)
36 : Thread (
"ContentSharer::PrepareImagesThread"),
39 imageFileFormat (imageFileFormatToUse ==
nullptr ? new PNGImageFormat()
40 : imageFileFormatToUse),
41 extension (imageFileFormat->getFormatName().toLowerCase())
46 ~PrepareImagesThread()
override
48 signalThreadShouldExit();
49 waitForThreadToExit (10000);
55 for (
const auto& image : images)
57 if (threadShouldExit())
67 if (outputStream ==
nullptr)
70 if (imageFileFormat->writeImageToStream (image, *outputStream))
71 owner.temporaryFiles.add (tempFile);
79 MessageManager::callAsync ([
this]() { owner.filesToSharePrepared(); });
83 const Array<Image> images;
84 std::unique_ptr<ImageFileFormat> imageFileFormat;
89class ContentSharer::PrepareDataThread :
private Thread
92 PrepareDataThread (ContentSharer& cs,
const MemoryBlock& mb)
93 : Thread (
"ContentSharer::PrepareDataThread"),
100 ~PrepareDataThread()
override
102 signalThreadShouldExit();
103 waitForThreadToExit (10000);
113 if (
auto outputStream = std::unique_ptr<FileOutputStream> (tempFile.
createOutputStream()))
116 size_t totalSize =
data.getSize();
118 while (pos < totalSize)
120 if (threadShouldExit())
123 size_t numToWrite = std::min ((
size_t) 8192, totalSize - pos);
125 outputStream->write (
data.begin() + pos, numToWrite);
130 owner.temporaryFiles.add (tempFile);
139 MessageManager::callAsync ([
this]() { owner.filesToSharePrepared(); });
142 ContentSharer& owner;
143 const MemoryBlock
data;
154 std::function<
void (
bool,
const String&)> callbackToUse)
156 #if JUCE_CONTENT_SHARING
157 startNewShare (callbackToUse);
158 pimpl->shareFiles (
files);
166 callbackToUse (
false,
"Content sharing is not available on this platform!");
170#if JUCE_CONTENT_SHARING
171void ContentSharer::startNewShare (std::function<
void (
bool,
const String&)> callbackToUse)
178 prepareDataThread =
nullptr;
179 prepareImagesThread =
nullptr;
181 deleteTemporaryFiles();
185 callback = std::move (callbackToUse);
187 pimpl.reset (createPimpl());
192 std::function<
void (
bool,
const String&)> callbackToUse)
194 #if JUCE_CONTENT_SHARING
195 startNewShare (callbackToUse);
196 pimpl->shareText (
text);
204 callbackToUse (
false,
"Content sharing is not available on this platform!");
209 std::function<
void (
bool,
const String&)> callbackToUse,
212 #if JUCE_CONTENT_SHARING
213 startNewShare (callbackToUse);
214 prepareImagesThread.reset (
new PrepareImagesThread (*
this, images, imageFileFormatToUse));
222 callbackToUse (
false,
"Content sharing is not available on this platform!");
226#if JUCE_CONTENT_SHARING
227void ContentSharer::filesToSharePrepared()
231 for (
const auto& tempFile : temporaryFiles)
232 urls.
add (
URL (tempFile));
234 prepareImagesThread =
nullptr;
235 prepareDataThread =
nullptr;
237 pimpl->shareFiles (urls);
242 std::function<
void (
bool,
const String&)> callbackToUse)
244 #if JUCE_CONTENT_SHARING
245 startNewShare (callbackToUse);
246 prepareDataThread.reset (
new PrepareDataThread (*
this, mb));
251 callbackToUse (
false,
"Content sharing not available on this platform!");
264 #if JUCE_CONTENT_SHARING
269 cb (succeeded,
error);
#define nullptr
Definition DistrhoDefines.h:75
static void run(LV2_Handle instance, uint32_t n_samples)
Definition bindings_test_plugin.c:112
static File createTempFile(StringRef fileNameEnding)
Definition File.cpp:953
Result create() const
Definition File.cpp:494
FileOutputStream * createOutputStream(size_t bufferSize=0x8000) const
Definition File.cpp:743
bool wasOk() const noexcept
Definition Result.cpp:68
Definition juce_Array.h:56
void add(const ElementType &newElement)
Definition juce_Array.h:418
void shareText(const String &text, std::function< void(bool, const String &)> callback)
Definition juce_ContentSharer.cpp:191
void shareData(const MemoryBlock &mb, std::function< void(bool, const String &)> callback)
Definition juce_ContentSharer.cpp:241
std::function< void(bool, String)> callback
Definition juce_ContentSharer.h:110
~ContentSharer()
Definition juce_ContentSharer.cpp:151
Array< File > temporaryFiles
Definition juce_ContentSharer.h:108
void deleteTemporaryFiles()
Definition juce_ContentSharer.cpp:272
ContentSharer()
Definition juce_ContentSharer.cpp:150
void shareImages(const Array< Image > &images, std::function< void(bool, const String &)> callback, ImageFileFormat *imageFileFormatToUse=nullptr)
Definition juce_ContentSharer.cpp:208
void sharingFinished(bool, const String &)
Definition juce_ContentSharer.cpp:255
void shareFiles(const Array< URL > &files, std::function< void(bool, const String &)> callback)
Definition juce_ContentSharer.cpp:153
Definition juce_MemoryBlock.h:33
Definition juce_String.h:53
unsigned f
Definition inflate.c:1572
JSAMPIMAGE data
Definition jpeglib.h:945
#define JUCE_IMPLEMENT_SINGLETON(Classname)
Definition juce_Singleton.h:201
static char ** files
Definition misc.c:28
Definition carla_juce.cpp:31
void ignoreUnused(Types &&...) noexcept
Definition juce_MathsFunctions.h:333
const char * text
Definition swell-functions.h:167
RECT const char void(* callback)(const char *droppath))) SWELL_API_DEFINE(BOOL
Definition swell-functions.h:1004
#define void
Definition unzip.h:396