47 NullCheckedInvocation::invoke (callback,
false,
"Content sharing not available on this platform!");
55 virtual void close() {}
75 callback = std::move (
cb);
79 std::tie (temporaryFiles, error) = prepareTemporaryFiles();
93 void handleAsyncUpdate()
override
97 NullCheckedInvocation::invoke (callback,
false, error);
101 inner = shareFiles (temporaryFiles, parent);
103 if (inner ==
nullptr)
105 NullCheckedInvocation::invoke (callback,
false,
TRANS (
"Failed to create file sharer"));
109 inner->runAsync (callback);
133 const auto extension = format->getFormatName().toLowerCase();
137 for (
const auto& image : images)
139 File tempFile = File::createTempFile (extension);
146 if (outputStream ==
nullptr)
147 return { Array<URL>{},
TRANS (
"Failed to open temporary file for writing") };
149 if (
format->writeImageToStream (image, *outputStream))
150 result.
add (URL (tempFile));
157 return url.isLocalFile() && url.getLocalFile().existsAsFile();
160 return { std::move (result), String{} };
167 return std::make_unique<Decorator> (images,
168 format ==
nullptr ? std::make_unique<PNGImageFormat>() :
std::
move (
format),
174 class Decorator :
public TemporaryFilesDecorator
177 Decorator (MemoryBlock mbIn, Component* parentIn)
178 : TemporaryFilesDecorator (parentIn), mb (
std::
move (mbIn)) {}
183 File tempFile = File::createTempFile (
"data");
185 if (! tempFile.create().wasOk())
186 return { Array<URL>{},
TRANS (
"Failed to create temporary file") };
190 if (outputStream ==
nullptr)
191 return { Array<URL>{},
TRANS (
"Failed to open temporary file for writing") };
194 size_t totalSize = mb.getSize();
196 while (pos < totalSize)
198 size_t numToWrite =
std::min ((
size_t) 8192, totalSize - pos);
200 if (! outputStream->write (mb.begin() + pos, numToWrite))
201 return { Array<URL>{},
TRANS (
"Failed to write to temporary file") };
206 return { Array<URL> { URL (tempFile) }, String{} };
212 return std::make_unique<Decorator> (std::move (
mb), parent);
Holds a resizable array of primitive or copy-by-value objects.
ElementType * begin() noexcept
Returns a pointer to the first element in the array.
ElementType * end() noexcept
Returns a pointer to the element which follows the last element in the array.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
Has a callback method that is triggered asynchronously.
void triggerAsyncUpdate()
Causes the callback to be triggered at a later time.
The base class for all JUCE user-interface objects.
Represents a local file or directory.
std::unique_ptr< FileOutputStream > createOutputStream(size_t bufferSize=0x8000) const
Creates a stream to write to this file.
Result create() const
Creates an empty file if it doesn't already exist.
A class to hold a resizable block of raw data.
bool wasOk() const noexcept
Returns true if this result indicates a success.
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
#define TRANS(stringLiteral)
Uses the LocalisedStrings class to translate the given string literal.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...