Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qohossharekit.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtHarmonyExtras/private/qohossharekitbackend_p.h>
7
8#include <QtGui/qwindow.h>
9
10#include <QtCore/qmimedatabase.h>
11#include <QtCore/private/qohoscommon_p.h>
12#include <QtCore/private/qohoslogger_p.h>
13
15
16namespace QtHarmonyExtras {
17
18using namespace Private;
19
20/*!
21 \namespace QtHarmonyExtras::ShareKit
22 \inmodule QtHarmonyExtras
23 \since 5.12.12
24 \brief The ShareKit to expose Share Kit API.
25*/
26namespace ShareKit {
27
28namespace {
29
30constexpr const char *mimeTextUriList = "text/uri-list";
31
32std::optional<QOhosShareKit::ShareAbilityType> tryMapShareAbilityTypeToShareKitEnum(
33 ShareAbilityType abilityType)
34{
35 switch (abilityType) {
36 case ShareAbilityType::CopyToPasteboard:
37 return std::make_optional(QOhosShareKit::ShareAbilityType::COPY_TO_PASTEBOARD);
38 case ShareAbilityType::SaveToMediaAsset:
39 return std::make_optional(QOhosShareKit::ShareAbilityType::SAVE_TO_MEDIA_ASSET);
40 case ShareAbilityType::SaveAsFile:
41 return std::make_optional(QOhosShareKit::ShareAbilityType::SAVE_AS_FILE);
42 case ShareAbilityType::Print:
43 return std::make_optional(QOhosShareKit::ShareAbilityType::PRINT);
44 case ShareAbilityType::SaveToSuperHub:
45 return std::make_optional(QOhosShareKit::ShareAbilityType::SAVE_TO_SUPERHUB);
46 }
47
48 return {};
49}
50
51std::vector<QOhosShareKit::ShareAbilityType> mapExcludedAbilitiesToShareKit(
52 const QList<ShareAbilityType> &excludedAbilities)
53{
54 std::vector<QOhosShareKit::ShareAbilityType> shareKitExcludedAbilities;
55 for (auto excludedAbilityType : excludedAbilities) {
56 auto optShareKitExcludedAbilityType = tryMapShareAbilityTypeToShareKitEnum(excludedAbilityType);
57 if (optShareKitExcludedAbilityType.has_value())
58 shareKitExcludedAbilities.push_back(optShareKitExcludedAbilityType.value());
59 }
60 return shareKitExcludedAbilities;
61}
62
63class SharedRecordImpl : public SharedRecord
64{
65public:
66 SharedRecordImpl(const QMimeType &mimeType, const QString &content, bool urlContent);
67 SharedRecordImpl(const QFileInfo &fileInfo);
68
69 QMimeType mimeType() const override;
70 QString content() const override;
71 QString filePath() const override;
72 bool isUrlContent() const override;
73
74 void setTitle(const QString &title) override;
75 QString title() const override;
76
77 void setLabel(const QString &label) override;
78 QString label() const override;
79
80 void setDescription(const QString &description) override;
81 QString description() const override;
82
83 void setThumbnail(const QByteArray &thumbnail) override;
84 QByteArray thumbnail() const override;
85
86 void setThumbnailFilePath(const QString &thumbnailFilePath) override;
87 QString thumbnailFilePath() const override;
88
89 void setExtraData(const QVariantMap &extraData) override;
90 QVariantMap extraData() const override;
91
92private:
93 QMimeType m_mimeType;
94 std::optional<QString> m_content;
95 std::optional<QString> m_filePath;
96 bool m_urlContent;
97 std::optional<QString> m_title;
98 std::optional<QString> m_label;
99 std::optional<QString> m_description;
100 std::optional<QByteArray> m_thumbnail;
101 std::optional<QString> m_thumbnailFilePath;
102 std::optional<QVariantMap> m_extraData;
103};
104
105SharedRecordImpl::SharedRecordImpl(const QMimeType &mimeType, const QString &content, bool urlContent)
106 : SharedRecord()
107 , m_mimeType(mimeType)
108 , m_content(content)
109 , m_urlContent(urlContent)
110{
111}
112
113SharedRecordImpl::SharedRecordImpl(const QFileInfo &fileInfo)
114 : SharedRecord()
115 , m_mimeType(QMimeDatabase().mimeTypeForFile(fileInfo))
116 , m_filePath(fileInfo.absoluteFilePath())
117 , m_urlContent(false)
118{
119}
120
121QMimeType SharedRecordImpl::mimeType() const
122{
123 return m_mimeType;
124}
125
126QString SharedRecordImpl::content() const
127{
128 return m_content.value_or(QString());
129}
130
131QString SharedRecordImpl::filePath() const
132{
133 return m_filePath.value_or(QString());
134}
135
136bool SharedRecordImpl::isUrlContent() const
137{
138 return m_urlContent;
139}
140
141void SharedRecordImpl::setTitle(const QString &title)
142{
143 m_title = title;
144}
145
146QString SharedRecordImpl::title() const
147{
148 return m_title.value_or(QString());
149}
150
151void SharedRecordImpl::setLabel(const QString &label)
152{
153 m_label = label;
154}
155
156QString SharedRecordImpl::label() const
157{
158 return m_label.value_or(QString());
159}
160
161void SharedRecordImpl::setDescription(const QString &description)
162{
163 m_description = description;
164}
165
166QString SharedRecordImpl::description() const
167{
168 return m_description.value_or(QString());
169}
170
171void SharedRecordImpl::setThumbnail(const QByteArray &thumbnail)
172{
173 m_thumbnail = thumbnail;
174}
175
176QByteArray SharedRecordImpl::thumbnail() const
177{
178 return m_thumbnail.value_or(QByteArray());
179}
180
181void SharedRecordImpl::setThumbnailFilePath(const QString &thumbnailFilePath)
182{
183 m_thumbnailFilePath = thumbnailFilePath;
184}
185
186QString SharedRecordImpl::thumbnailFilePath() const
187{
188 return m_thumbnailFilePath.value_or(QString());
189}
190
191void SharedRecordImpl::setExtraData(const QVariantMap &extraData)
192{
193 m_extraData = extraData;
194}
195
196QVariantMap SharedRecordImpl::extraData() const
197{
198 return m_extraData.value_or(QVariantMap());
199}
200
201class ShareControllerOptionsImpl : public ShareControllerOptions
202{
203public:
204 void setAnchorOffset(QPoint anchorOffset) override;
205 void setAnchor(QRect anchor) override;
206 std::optional<QPoint> anchorOffset() const;
207 std::optional<QSize> anchorSize() const;
208
209 void setSingleSelectionMode(bool singleSelectionMode) override;
210 std::optional<bool> isSingleSelection() const;
211
212 void setDefaultPreviewMode(bool defaultPreviewMode) override;
213 std::optional<bool> isDefaultPreview() const;
214
215 void setExcludedAbilities(const QList<ShareAbilityType> &excludedAbilities) override;
216 std::optional<QList<ShareAbilityType>> excludedAbilities() const;
217
218private:
219 std::optional<QPoint> m_anchorOffset;
220 std::optional<QSize> m_anchorSize;
221 std::optional<bool> m_singleSelectionMode;
222 std::optional<bool> m_defaultPreviewMode;
223 std::optional<QList<ShareAbilityType>> m_excludedAbilities;
224};
225
226void ShareControllerOptionsImpl::setAnchorOffset(QPoint anchorOffset)
227{
228 m_anchorOffset = anchorOffset;
229}
230
231void ShareControllerOptionsImpl::setAnchor(QRect anchor)
232{
233 m_anchorOffset = anchor.topLeft();
234 m_anchorSize = anchor.size();
235}
236
237std::optional<QPoint> ShareControllerOptionsImpl::anchorOffset() const
238{
239 return m_anchorOffset;
240}
241
242std::optional<QSize> ShareControllerOptionsImpl::anchorSize() const
243{
244 return m_anchorSize;
245}
246
247void ShareControllerOptionsImpl::setSingleSelectionMode(bool singleSelectionMode)
248{
249 m_singleSelectionMode = singleSelectionMode;
250}
251
252std::optional<bool> ShareControllerOptionsImpl::isSingleSelection() const
253{
254 return m_singleSelectionMode;
255}
256
257void ShareControllerOptionsImpl::setDefaultPreviewMode(bool defaultPreviewMode)
258{
259 m_defaultPreviewMode = defaultPreviewMode;
260}
261
262std::optional<bool> ShareControllerOptionsImpl::isDefaultPreview() const
263{
264 return m_defaultPreviewMode;
265}
266
267void ShareControllerOptionsImpl::setExcludedAbilities(const QList<ShareAbilityType> &excludedAbilities)
268{
269 m_excludedAbilities = excludedAbilities;
270}
271
272std::optional<QList<ShareAbilityType>> ShareControllerOptionsImpl::excludedAbilities() const
273{
274 return m_excludedAbilities;
275}
276
277class ShareOperationResultImpl : public ShareOperationResult
278{
279public:
280 ShareOperationResultImpl(
281 const QOhosShareKit::ShareOperationResult &shareOperationResult);
282
283 QString targetAbilityName() const override;
284
285private:
286 QString m_targetAbilityName;
287};
288
289ShareOperationResultImpl::ShareOperationResultImpl(
290 const QOhosShareKit::ShareOperationResult &shareOperationResult)
291 : ShareOperationResult()
292 , m_targetAbilityName(QString::fromStdString(shareOperationResult.targetAbilityName))
293{
294}
295
296QString ShareOperationResultImpl::targetAbilityName() const
297{
298 return m_targetAbilityName;
299}
300
301std::vector<QOhosShareKit::SharedRecord> convertToShareKitSharedRecords(
302 const QList<std::shared_ptr<SharedRecord>> &dataToShare)
303{
304 std::vector<QOhosShareKit::SharedRecord> records;
305
306 for (const auto &sharedRecord : dataToShare) {
307 const auto *sharedRecordImpl = static_cast<const SharedRecordImpl *>(sharedRecord.get());
308
309 auto shareKitSharedRecord = QOhosShareKit::SharedRecord{};
310 shareKitSharedRecord.mimeType = !sharedRecordImpl->isUrlContent()
311 ? sharedRecordImpl->mimeType().name().toStdString()
312 : std::string(mimeTextUriList);
313
314 if (!sharedRecordImpl->content().isNull()) {
315 shareKitSharedRecord.content = sharedRecordImpl->content().toStdString();
316 } else if (!sharedRecordImpl->filePath().isNull()) {
317 shareKitSharedRecord.filePath = sharedRecordImpl->filePath().toStdString();
318 } else {
319 qOhosPrintfWarning("%s: SharedRecord doesn't have content or uri, skipping...", Q_FUNC_INFO);
320 continue;
321 }
322
323 if (!sharedRecordImpl->title().isNull())
324 shareKitSharedRecord.title = sharedRecordImpl->title().toStdString();
325 if (!sharedRecordImpl->label().isNull())
326 shareKitSharedRecord.label = sharedRecordImpl->label().toStdString();
327 if (!sharedRecordImpl->description().isNull())
328 shareKitSharedRecord.description = sharedRecordImpl->description().toStdString();
329 if (!sharedRecordImpl->thumbnail().isNull())
330 shareKitSharedRecord.thumbnail = sharedRecordImpl->thumbnail();
331 if (!sharedRecordImpl->thumbnailFilePath().isNull())
332 shareKitSharedRecord.thumbnailFilePath = sharedRecordImpl->thumbnailFilePath().toStdString();
333 if (!sharedRecordImpl->extraData().isEmpty())
334 shareKitSharedRecord.extraData = sharedRecordImpl->extraData();
335
336 records.push_back(shareKitSharedRecord);
337 }
338
339 return records;
340}
341
342}
343
344/*!
345 \class QtHarmonyExtras::ShareKit::SharedRecord
346 \inmodule QtHarmonyExtras
347 \since 5.12.12
348 \brief The SharedRecord class encapsulates the content and metadata to be shared with another application.
349
350 A SharedRecord holds the data to be shared (text content, a file, or a URL) along with
351 optional metadata such as a title, label, description, and thumbnail. Instances are created
352 using QtHarmonyExtras::ShareKit::createContentRecord(),
353 QtHarmonyExtras::ShareKit::createFileRecord(), or QtHarmonyExtras::ShareKit::createUrlRecord(),
354 and are then passed to the share controller to be shared with other applications.
355
356 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
357 {SharedRecord}.
358
359 \sa QtHarmonyExtras::ShareKit::createContentRecord(), QtHarmonyExtras::ShareKit::createFileRecord(),
360 QtHarmonyExtras::ShareKit::createUrlRecord()
361*/
362
363/*!
364 \fn virtual QMimeType QtHarmonyExtras::ShareKit::SharedRecord::mimeType() const = 0
365
366 Gets the shared record associated mime type.
367 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
368 {SharedRecord.utd}
369*/
370
371/*!
372 \fn virtual QString QtHarmonyExtras::ShareKit::SharedRecord::content() const = 0
373
374 Gets the shared record optional content. Either content or file path must be set. If there is no content null string is provided.
375 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
376 {SharedRecord.content}
377*/
378
379/*!
380 \fn virtual QString QtHarmonyExtras::ShareKit::SharedRecord::filePath() const = 0
381
382 Gets the shared record optional file path. Either content or file path must be set. If there is no file path null string is provided.
383 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
384 {SharedRecord.content}
385*/
386
387/*!
388 \fn virtual bool QtHarmonyExtras::ShareKit::SharedRecord::isUrlContent() const = 0
389
390 Provides information if content() contains URL string. For URL content the mimeType() should not be used.
391 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
392 {SharedRecord.content}
393*/
394
395/*!
396 \fn virtual void QtHarmonyExtras::ShareKit::SharedRecord::setTitle(const QString &title) = 0
397
398 Sets the title of shared content with a given \a title.
399 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
400 {SharedRecord.title}
401*/
402
403/*!
404 \fn virtual QString QtHarmonyExtras::ShareKit::SharedRecord::title() const = 0
405
406 Gets the optional title of the shared record. If there is no title null string is provided.
407 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
408 {SharedRecord.title}
409*/
410
411/*!
412 \fn virtual void QtHarmonyExtras::ShareKit::SharedRecord::setLabel(const QString &label) = 0
413
414 Sets the label indicating the current data record type with a given \a label.
415 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
416 {SharedRecord.label}
417*/
418
419/*!
420 \fn virtual QString QtHarmonyExtras::ShareKit::SharedRecord::label() const = 0
421
422 Gets the optional label of the shared record. If there is no label null string is provided.
423 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
424 {SharedRecord.label}
425*/
426
427/*!
428 \fn virtual void QtHarmonyExtras::ShareKit::SharedRecord::setDescription(const QString &description) = 0
429
430 Sets data record description with a given \a description.
431 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
432 {SharedRecord.description}
433*/
434
435/*!
436 \fn virtual QString QtHarmonyExtras::ShareKit::SharedRecord::description() const = 0
437
438 Gets the optional description of the shared record. If there is no description null string is provided.
439 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
440 {SharedRecord.description}
441*/
442
443/*!
444 \fn virtual void QtHarmonyExtras::ShareKit::SharedRecord::setThumbnail(const QByteArray &thumbnail) = 0
445
446 Sets data record thumbnail with a given \a thumbnail. The thumbnail is an image file content.
447 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
448 {SharedRecord.thumbnail}
449*/
450
451/*!
452 \fn virtual QByteArray QtHarmonyExtras::ShareKit::SharedRecord::thumbnail() const = 0
453
454 Gets the optional thumbnail content of the shared record. If there is no thumbnail empty byte array is provided.
455 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
456 {SharedRecord.thumbnail}
457*/
458
459/*!
460 \fn virtual void QtHarmonyExtras::ShareKit::SharedRecord::setThumbnailFilePath(const QString &thumbnailFilePath) = 0
461
462 Sets data record thumbnail uri with a given \a thumbnailFilePath.
463 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
464 {SharedRecord.thumbnailUri}
465*/
466
467/*!
468 \fn virtual QString QtHarmonyExtras::ShareKit::SharedRecord::thumbnailFilePath() const = 0
469
470 Gets the optional thumbnail file path of the shared record. If there is no thumbnail file path null string is provided.
471 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
472 {SharedRecord.thumbnailFilePath}
473*/
474
475/*!
476 \fn virtual void QtHarmonyExtras::ShareKit::SharedRecord::setExtraData(const QVariantMap &extraData) = 0
477
478 Sets exatra data for sharing with a given \a extraData.
479 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
480 {SharedRecord.extraData}
481*/
482
483/*!
484 \fn virtual QVariantMap QtHarmonyExtras::ShareKit::SharedRecord::extraData() const = 0
485
486 Gets the optional extra data of the shared record. If there is no extra data empty variant map is provided.
487 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
488 {SharedRecord.extraData}
489*/
490
491SharedRecord::SharedRecord() = default;
492SharedRecord::~SharedRecord() = default;
493
494/*!
495 \class QtHarmonyExtras::ShareKit::ShareControllerOptions
496 \inmodule QtHarmonyExtras
497 \since 5.12.12
498 \brief The ShareControllerOptions class is to configure items, such as the preview mode of the shared content, selection mode,
499 and other information, and pop-up window anchor. It determines the display style of the sharing panel.
500 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section107934816010}
501 {ShareControllerOptions}
502*/
503
504/*!
505 \fn virtual void QtHarmonyExtras::ShareKit::ShareControllerOptions::setAnchorOffset(QPoint anchorOffset) = 0
506
507 Sets sharing pop-up window anchor window offset with a given \a anchorOffset.
508 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section107934816010}
509 {ShareControllerOptions.anchor}
510*/
511
512/*!
513 \fn virtual void QtHarmonyExtras::ShareKit::ShareControllerOptions::setAnchor(QRect anchor) = 0
514
515 Sets anchor offset and size with a given \a anchor.
516 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section19505934714}
517 {ShareControllerAnchor}
518*/
519
520/*!
521 \fn virtual void QtHarmonyExtras::ShareKit::ShareControllerOptions::setSingleSelectionMode(bool singleSelectionMode) = 0
522
523 Sets sharing selection mode with a given \a singleSelectionMode. If singleSelectionMode is true,
524 single selection is set, batch mode otherwise.
525 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section107934816010}
526 {ShareControllerOptions.selectionMode}
527*/
528
529
530/*!
531 \fn virtual void QtHarmonyExtras::ShareKit::ShareControllerOptions::setDefaultPreviewMode(bool defaultPreviewMode) = 0
532
533 Set sharing panel preview mode with a given \a defaultPreviewMode. If defaultPreviewMode is true, default preview
534 mode (thumbnail card) is set, detail mode otherwise. Detail mode is recommended for images and videos.
535 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section107934816010}
536 {ShareControllerOptions.previewMode}
537*/
538
539/*!
540 \fn virtual void QtHarmonyExtras::ShareKit::ShareControllerOptions::setExcludedAbilities(const QList<ShareAbilityType> &excludedAbilities) = 0
541
542 Set a list of capabilities that do not need to be displayed in the operation area.
543 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section107934816010}
544 {ShareControllerOptions.excludedAbilities}
545*/
546
549
550/*!
551 \class QtHarmonyExtras::ShareKit::ShareOperationResult
552 \inmodule QtHarmonyExtras
553 \since 5.12.12
554 \brief ShareOperationResult wraps Ohos \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section17135118312}
555 {ShareOperationResult} interface.
556
557 It keeps information about share target ability.
558*/
559
560/*!
561 \fn virtual QString QtHarmonyExtras::ShareKit::ShareOperationResult::targetAbilityName() const = 0
562
563 Gets the target ability name. For more info how the name is built please check following link.
564 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
565 {SharedRecord.utd}
566*/
567
570
571/*!
572 \fn std::shared_ptr<QtHarmonyExtras::ShareKit::SharedRecord> QtHarmonyExtras::ShareKit::createContentRecord(const QMimeType &mimeType, const QString &content)
573
574 Creates a shared "content" record with a given \a mimeType and \a content. Shared record can be created
575 with content (this function) or as a file shared record \sa QtHarmonyExtras::ShareKit::createFileRecord().
576 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
577 {SharedRecord.content}
578*/
580 const QMimeType &mimeType, const QString &content)
581{
582 return std::make_shared<SharedRecordImpl>(mimeType, content, false);
583}
584
585/*!
586 \fn std::shared_ptr<QtHarmonyExtras::ShareKit::SharedRecord> QtHarmonyExtras::ShareKit::createFileRecord(const QFileInfo &fileInfo)
587
588 Creates a shared "file" record with a given \a fileInfo. Shared record can be created
589 with file (this function) or as a content record \sa QtHarmonyExtras::ShareKit::createContentRecord().
590 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
591 {SharedRecord.uri}
592*/
593std::shared_ptr<SharedRecord> createFileRecord(const QFileInfo &fileInfo)
594{
595 return std::make_shared<SharedRecordImpl>(fileInfo);
596}
597
598/*!
599 \fn std::shared_ptr<QtHarmonyExtras::ShareKit::SharedRecord> QtHarmonyExtras::ShareKit::createUrlRecord(const QUrl &url)
600
601 Creates a shared record with a given \a url.
602 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section20696483813}
603 {SharedRecord.content}
604*/
606{
607 return std::make_shared<SharedRecordImpl>(QMimeType(), url.toString(), true);
608}
609
610/*!
611 \fn std::shared_ptr<QtHarmonyExtras::ShareKit::ShareControllerOptions> QtHarmonyExtras::ShareKit::createControllerOptions()
612
613 Creates a controller options instnace. Controller options can be used to configure preview mode,
614 selection mode and pop-up window anchor.
615 See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references/share-system-share#section107934816010}
616 {ShareControllerOptions}
617*/
619{
620 return std::make_shared<ShareControllerOptionsImpl>();
621}
622
623}
624
625namespace Private {
626
627using namespace ShareKit;
628
629std::shared_ptr<void> shareData(
630 QWindow *optMainWindow, const QList<std::shared_ptr<SharedRecord>> &records,
631 std::shared_ptr<ShareControllerOptions> controllerOptions,
632 std::function<void()> panelClosedCallback,
633 std::function<void(std::shared_ptr<ShareKit::ShareOperationResult>)> shareCompletedCallback)
634{
635 QOhosShareKit::ControllerOptions shareKitControllerOptions;
636 if (controllerOptions) {
637 const auto *controllerOptionsImpl = static_cast<const ShareControllerOptionsImpl *>(controllerOptions.get());
638
639 const auto optAnchorOffset = controllerOptionsImpl->anchorOffset();
640 if (optAnchorOffset.has_value()) {
641 shareKitControllerOptions.anchor = QOhosShareKit::ShareControllerAnchor{
642 .windowOffset = optAnchorOffset.value(),
643 .size = controllerOptionsImpl->anchorSize(),
644 };
645 }
646
647 const auto optSingleSelection = controllerOptionsImpl->isSingleSelection();
648 if (optSingleSelection.has_value()) {
649 shareKitControllerOptions.selectionMode = optSingleSelection.value()
650 ? QOhosShareKit::SelectionMode::SINGLE
651 : QOhosShareKit::SelectionMode::BATCH;
652 }
653
654 const auto optDefaultPreview = controllerOptionsImpl->isDefaultPreview();
655 if (optDefaultPreview.has_value()) {
656 shareKitControllerOptions.previewMode = optDefaultPreview.value()
657 ? QOhosShareKit::SharePreviewMode::DEFAULT
658 : QOhosShareKit::SharePreviewMode::DETAIL;
659 }
660
661 const auto optExcludedAbilities = controllerOptionsImpl->excludedAbilities();
662 if (optExcludedAbilities.has_value())
663 shareKitControllerOptions.excludedAbilities =
664 mapExcludedAbilitiesToShareKit(optExcludedAbilities.value());
665 }
666
667 return QOhosShareKit::shareData(
668 optMainWindow, convertToShareKitSharedRecords(records), shareKitControllerOptions,
669 std::move(panelClosedCallback),
670 [shareCompletedCallback = std::move(shareCompletedCallback)](auto shareOperationResult) {
671 shareCompletedCallback(std::make_shared<ShareOperationResultImpl>(shareOperationResult));
672 });
673}
674
675}
676
677}
678
679QT_END_NAMESPACE
Combined button and popup list for selecting options.
std::shared_ptr< void > shareData(QWindow *optMainWindow, const QList< std::shared_ptr< SharedRecord > > &records, std::shared_ptr< ShareControllerOptions > controllerOptions, std::function< void()> panelClosedCallback, std::function< void(std::shared_ptr< ShareKit::ShareOperationResult >)> shareCompletedCallback)
std::shared_ptr< SharedRecord > createUrlRecord(const QUrl &url)
Creates a shared record with a given url.
std::shared_ptr< SharedRecord > createFileRecord(const QFileInfo &fileInfo)
Creates a shared "file" record with a given fileInfo.
std::shared_ptr< SharedRecord > createContentRecord(const QMimeType &mimeType, const QString &content)
Creates a shared "content" record with a given mimeType and content.
std::shared_ptr< ShareControllerOptions > createControllerOptions()
Creates a controller options instnace.